वेब ऐप्लिकेशन में OpenID Connect का इस्तेमाल करके पुष्टि करें
संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
अगर आपके पास Firebase Authentication with Identity Platform पर अपग्रेड किया गया है, तो इससे अपने उपयोगकर्ताओं की पुष्टि की जा सकती है:
आपकी पसंद के हिसाब से बनी, Open Connect (OIDC) कंपनी का इस्तेमाल करने वाला Firebase. यह
इससे ऐसे आइडेंटिटी प्रोवाइडर का इस्तेमाल किया जा सकता है जो Firebase में नेटिव तौर पर काम नहीं करता.
शुरू करने से पहले
किसी OIDC कंपनी का इस्तेमाल करके साइन इन करने के लिए, आपको पहले कुछ जानकारी इकट्ठा करनी होगी
से ठीक है:
Client-ID: सेवा देने वाली कंपनी के लिए यूनीक स्ट्रिंग, जो आपके ऐप्लिकेशन की पहचान करती है. आपका
ऐसा हो सकता है कि सेवा देने वाली कंपनी, आपके साथ काम करने वाले हर प्लैटफ़ॉर्म के लिए आपको एक अलग क्लाइंट आईडी असाइन करे.
यह आईडी टोकन में aud
दावे की वैल्यू में से एक है
कंपनी.
क्लाइंट सीक्रेट: ऐसी सीक्रेट स्ट्रिंग जिसका इस्तेमाल सेवा देने वाली कंपनी, मालिकाना हक की पुष्टि करने के लिए करती है
डालें. हर क्लाइंट आईडी के लिए, आपके पास मैच करने वाला क्लाइंट सीक्रेट होना चाहिए.
(यह वैल्यू सिर्फ़ तब ज़रूरी होती है, जब ऑथराइज़ेशन कोड फ़्लो का इस्तेमाल किया जा रहा हो, जो
का सुझाव दिया जाता है.)
जारी करने वाला: ऐसी स्ट्रिंग जिससे सेवा देने वाली कंपनी की पहचान होती है. यह मान एक URL होना चाहिए
जिसे /.well-known/openid-configuration
के साथ जोड़े जाने पर, जगह
को हटाने का अनुरोध किया है. उदाहरण के लिए, अगर जारी करने वाला
https://auth.example.com
, खोज से जुड़ा दस्तावेज़ यहां उपलब्ध होना चाहिए
https://auth.example.com/.well-known/openid-configuration
.
ऊपर दी गई जानकारी मिलने के बाद, साइन इन के तौर पर OpenID Connect को चालू करें
कंपनी:
Firebase को अपने JavaScript प्रोजेक्ट में जोड़ें.
अगर आपने Firebase Authentication with Identity Platform पर अपग्रेड नहीं किया है, तो ऐसा करें. OpenID Connect से पुष्टि करना
केवल अपग्रेड किए गए प्रोजेक्ट में उपलब्ध है.
साइन-इन करने की सुविधा देने वाली कंपनियों पर
Firebase कंसोल के पेज पर जाएं, नई कंपनी जोड़ें पर क्लिक करें और फिर
OpenID Connect.
चुनें कि आपको ऑथराइज़ेशन कोड फ़्लो का इस्तेमाल करना है या
इंप्लिसिट ग्रांट फ़्लो.
अगर सेवा देने वाली कंपनी यह सुविधा देती है, तो आपको हमेशा कोड फ़्लो का इस्तेमाल करना चाहिए. कॉन्टेंट बनाने
इंप्लिसिट फ़्लो कम सुरक्षित होता है. इसलिए, इसका इस्तेमाल करने की सलाह नहीं दी जाती.
इस कंपनी को एक नाम दें. जनरेट किए गए, सेवा देने वाले के आईडी को नोट करें:
oidc.example-provider
जैसा कुछ. खातों को जोड़ते समय आपको इस आईडी की ज़रूरत होगी
अपने ऐप्लिकेशन में साइन-इन कोड डालें.
अपना क्लाइंट आईडी, क्लाइंट सीक्रेट, और सेवा देने वाली कंपनी के जारी करने वाले की स्ट्रिंग के बारे में बताएं.
ये वैल्यू, उन वैल्यू से पूरी तरह मेल खानी चाहिए जो आपको सेवा देने वाली कंपनी ने असाइन की हैं.
बदलावों को सेव करें.
Firebase SDK टूल की मदद से साइन-इन की प्रोसेस को मैनेज करना
OIDC का इस्तेमाल करके, Firebase से अपने उपयोगकर्ताओं की पुष्टि करने का सबसे आसान तरीका
provider को Firebase SDK टूल के साथ साइन-इन की पूरी प्रोसेस मैनेज करनी होगी.
Firebase JavaScript SDK टूल से साइन-इन फ़्लो को मैनेज करने के लिए, इन निर्देशों का पालन करें
चरण:
आपको जो प्रोवाइडर आईडी मिला है उसका इस्तेमाल करके, OAuthProvider
का इंस्टेंस बनाएं
Firebase कंसोल.
Web
import { OAuthProvider } from "firebase/auth";
const provider = new OAuthProvider('oidc.example-provider');
Web
var provider = new firebase.auth.OAuthProvider('oidc.example-provider');
ज़रूरी नहीं: ऐसे अतिरिक्त कस्टम OAuth पैरामीटर तय करें जिन्हें आपको इस्तेमाल करना है
OAuth अनुरोध के साथ भेजें.
Web
provider.setCustomParameters({
// Target specific email with login hint.
login_hint: 'user@example.com'
});
Web
provider.setCustomParameters({
// Target specific email with login hint.
login_hint: 'user@example.com'
});
अपनी कंपनी से संपर्क करके जानें कि इसके साथ काम करने वाले पैरामीटर कौनसे हैं.
ध्यान दें कि आप Firebase के लिए ज़रूरी पैरामीटर को
setCustomParameters
. ये पैरामीटर client_id
हैं,
response_type
, redirect_uri
, state
, scope
, और
response_mode
.
ज़रूरी नहीं: बेसिक प्रोफ़ाइल के अलावा, OAuth 2.0 के अन्य दायरे तय करें.
पुष्टि करने की सेवा देने वाली कंपनी से अनुरोध करें.
Web
provider.addScope('mail.read');
provider.addScope('calendars.read');
Web
provider.addScope('mail.read');
provider.addScope('calendars.read');
अपनी कंपनी से संपर्क करके जानें कि वह किन स्कोप के साथ काम करता है.
OAuth प्रोवाइडर ऑब्जेक्ट का इस्तेमाल करके, Firebase से पुष्टि करें.
उपयोगकर्ता को या तो सेवा देने वाली कंपनी के साइन-इन पेज पर रीडायरेक्ट किया जा सकता है या
पॉप-अप ब्राउज़र विंडो में साइन-इन पेज पर.
रीडायरेक्ट फ़्लो
signInWithRedirect()
पर कॉल करके, सेवा देने वाली कंपनी के साइन-इन पेज पर रीडायरेक्ट करें:
Web
import { getAuth, signInWithRedirect } from "firebase/auth";
const auth = getAuth();
signInWithRedirect(auth, provider);
Web
firebase.auth().signInWithRedirect(provider);
उपयोगकर्ता के साइन-इन करने और आपके ऐप्लिकेशन पर वापस लौटने के बाद, आपको
getRedirectResult()
पर कॉल करके साइन-इन परिणाम.
Web
import { getAuth, getRedirectResult, OAuthProvider } from "firebase/auth";
const auth = getAuth();
getRedirectResult(auth)
.then((result) => {
// User is signed in.
// IdP data available in result.additionalUserInfo.profile.
// Get the OAuth access token and ID Token
const credential = OAuthProvider.credentialFromResult(result);
const accessToken = credential.accessToken;
const idToken = credential.idToken;
})
.catch((error) => {
// Handle error.
});
Web
firebase.auth().getRedirectResult()
.then((result) => {
// IdP data available in result.additionalUserInfo.profile.
// ...
/** @type {firebase.auth.OAuthCredential} */
var credential = result.credential;
// OAuth access and id tokens can also be retrieved:
var accessToken = credential.accessToken;
var idToken = credential.idToken;
})
.catch((error) => {
// Handle error.
});
पॉप-अप फ़्लो
Web
import { getAuth, signInWithPopup, OAuthProvider } from "firebase/auth";
const auth = getAuth();
signInWithPopup(auth, provider)
.then((result) => {
// User is signed in.
// IdP data available using getAdditionalUserInfo(result)
// Get the OAuth access token and ID Token
const credential = OAuthProvider.credentialFromResult(result);
const accessToken = credential.accessToken;
const idToken = credential.idToken;
})
.catch((error) => {
// Handle error.
});
Web
firebase.auth().signInWithPopup(provider)
.then((result) => {
// IdP data available in result.additionalUserInfo.profile.
// ...
/** @type {firebase.auth.OAuthCredential} */
var credential = result.credential;
// OAuth access and id tokens can also be retrieved:
var accessToken = credential.accessToken;
var idToken = credential.idToken;
})
.catch((error) => {
// Handle error.
});
ऊपर दिए गए उदाहरण, साइन-इन करने के फ़्लो पर फ़ोकस करते हैं. हालांकि, इनका इस्तेमाल भी किया जा सकता है
का इस्तेमाल करने वाले किसी मौजूदा उपयोगकर्ता से OIDC प्रोवाइडर को लिंक करने का पैटर्न
linkWithRedirect()
और linkWithPopup()
. साथ ही, इस सुविधा का इस्तेमाल करके किसी उपयोगकर्ता की फिर से पुष्टि करें
reauthenticateWithRedirect()
और reauthenticateWithPopup()
इनमें से कोई भी हो सकता है.
इसका इस्तेमाल, संवेदनशील कार्रवाइयों के लिए नए क्रेडेंशियल हासिल करने के लिए किया जाता है.
हाल ही का लॉगिन.
साइन-इन की प्रोसेस को मैन्युअल तरीके से मैनेज करना
अगर आपने अपने ऐप्लिकेशन में, Open Connect का साइन इन करने का फ़्लो पहले ही लागू कर दिया है, तो
Firebase से पुष्टि करने के लिए, सीधे आईडी टोकन का इस्तेमाल कर सकते हैं:
Web
import { getAuth, signInWithCredential, OAuthProvider } from "firebase/auth";
const provider = new OAuthProvider("oidc.example-provider");
const credential = provider.credential({
idToken: idToken,
});
signInWithCredential(getAuth(), credential)
.then((result) => {
// User is signed in.
// IdP data available in result.additionalUserInfo.profile.
// Get the OAuth access token and ID Token
const credential = OAuthProvider.credentialFromResult(result);
const accessToken = credential.accessToken;
const idToken = credential.idToken;
})
.catch((error) => {
// Handle error.
});
Web
const provider = new OAuthProvider("oidc.example-provider");
const credential = provider.credential({
idToken: idToken,
});
firebase.auth().signInWithCredential(credential)
.then((result) => {
// User is signed in.
// IdP data available in result.additionalUserInfo.profile.
// Get the OAuth access token and ID Token
const credential = OAuthProvider.credentialFromResult(result);
const accessToken = credential.accessToken;
const idToken = credential.idToken;
})
.catch((error) => {
// Handle error.
});
जब तक कुछ अलग से न बताया जाए, तब तक इस पेज की सामग्री को Creative Commons Attribution 4.0 License के तहत और कोड के नमूनों को Apache 2.0 License के तहत लाइसेंस मिला है. ज़्यादा जानकारी के लिए, Google Developers साइट नीतियां देखें. Oracle और/या इससे जुड़ी हुई कंपनियों का, Java एक रजिस्टर किया हुआ ट्रेडमार्क है.
आखिरी बार 2025-08-08 (UTC) को अपडेट किया गया.
[null,null,["आखिरी बार 2025-08-08 (UTC) को अपडेट किया गया."],[],[],null,["If you've upgraded to Firebase Authentication with Identity Platform, you can authenticate your users with\nFirebase using the OpenID Connect (OIDC) compliant provider of your choice. This\nmakes it possible to use identity providers not natively supported by Firebase.\n\nBefore you begin\n\nTo sign in users using an OIDC provider, you must first collect some information\nfrom the provider:\n\n- **Client ID** : A string unique to the provider that identifies your app. Your\n provider might assign you a different client ID for each platform you support.\n This is one of the values of the `aud` claim in ID tokens issued by your\n provider.\n\n- **Client secret** : A secret string that the provider uses to confirm ownership\n of a client ID. For every client ID, you will need a matching client secret.\n (This value is required only if you're using the *auth code flow*, which is\n strongly recommended.)\n\n- **Issuer** : A string that identifies your provider. This value must be a URL\n that, when appended with `/.well-known/openid-configuration`, is the location\n of the provider's OIDC discovery document. For example, if the issuer is\n `https://auth.example.com`, the discovery document must be available at\n `https://auth.example.com/.well-known/openid-configuration`.\n\nAfter you have the above information, enable OpenID Connect as a sign-in\nprovider for your Firebase project:\n\n1. [Add Firebase to your JavaScript project](/docs/web/setup).\n\n2. If you haven't upgraded to Firebase Authentication with Identity Platform, do so. OpenID Connect authentication\n is only available in upgraded projects.\n\n3. On the [**Sign-in providers**](//console.firebase.google.com/project/_/authentication/providers)\n page of the Firebase console, click **Add new provider** , and then click\n **OpenID Connect**.\n\n4. Select whether you will be using the *authorization code flow* or the\n *implicit grant flow*.\n\n **You should use always the code flow if your provider supports it**. The\n implicit flow is less secure and using it is strongly discouraged.\n5. Give a name to this provider. Note the provider ID that's generated:\n something like `oidc.example-provider`. You'll need this ID when you add\n sign-in code to your app.\n\n6. Specify your client ID and client secret, and your provider's issuer string.\n These values must exactly match the values your provider assigned to you.\n\n7. Save your changes.\n\nHandle the sign-in flow with the Firebase SDK\n\nThe easiest way to authenticate your users with Firebase using your OIDC\nprovider is to handle the entire sign-in flow with the Firebase SDK.\n\nTo handle the sign-in flow with the Firebase JavaScript SDK, follow these\nsteps:\n\n1. Create an instance of an `OAuthProvider` using the provider ID you got in\n the Firebase console.\n\n Web \n\n import { OAuthProvider } from \"firebase/auth\";\n\n const provider = new OAuthProvider('oidc.example-provider');\n\n Web \n\n var provider = new firebase.auth.OAuthProvider('oidc.example-provider');\n\n2. **Optional**: Specify additional custom OAuth parameters that you want to\n send with the OAuth request.\n\n Web \n\n provider.setCustomParameters({\n // Target specific email with login hint.\n login_hint: 'user@example.com'\n });\n\n Web \n\n provider.setCustomParameters({\n // Target specific email with login hint.\n login_hint: 'user@example.com'\n });\n\n Check with your provider for the parameters it supports.\n Note that you can't pass Firebase-required parameters with\n `setCustomParameters`. These parameters are `client_id`,\n `response_type`, `redirect_uri`, `state`, `scope` and\n `response_mode`.\n3. **Optional**: Specify additional OAuth 2.0 scopes beyond basic profile that\n you want to request from the authentication provider.\n\n Web \n\n provider.addScope('mail.read');\n provider.addScope('calendars.read');\n\n Web \n\n provider.addScope('mail.read');\n provider.addScope('calendars.read');\n\n Check with your provider for the scopes it supports.\n4. Authenticate with Firebase using the OAuth provider object.\n\n You can either redirect the user to the provider's sign-in page or open the\n sign-in page in a pop-up browser window.\n\n **Redirect flow**\n\n Redirect to the provider sign-in page by calling `signInWithRedirect()`: \n\n Web \n\n import { getAuth, signInWithRedirect } from \"firebase/auth\";\n\n const auth = getAuth();\n signInWithRedirect(auth, provider);\n\n Web \n\n firebase.auth().signInWithRedirect(provider);\n\n After the user completes sign-in and returns to your app, you can obtain the\n sign-in result by calling `getRedirectResult()`. \n\n Web \n\n import { getAuth, getRedirectResult, OAuthProvider } from \"firebase/auth\";\n\n const auth = getAuth();\n getRedirectResult(auth)\n .then((result) =\u003e {\n // User is signed in.\n // IdP data available in result.additionalUserInfo.profile.\n\n // Get the OAuth access token and ID Token\n const credential = OAuthProvider.credentialFromResult(result);\n const accessToken = credential.accessToken;\n const idToken = credential.idToken;\n })\n .catch((error) =\u003e {\n // Handle error.\n });\n\n Web \n\n firebase.auth().getRedirectResult()\n .then((result) =\u003e {\n // IdP data available in result.additionalUserInfo.profile.\n // ...\n\n /** @type {firebase.auth.OAuthCredential} */\n var credential = result.credential;\n\n // OAuth access and id tokens can also be retrieved:\n var accessToken = credential.accessToken;\n var idToken = credential.idToken;\n })\n .catch((error) =\u003e {\n // Handle error.\n });\n\n **Pop-up flow** \n\n Web \n\n import { getAuth, signInWithPopup, OAuthProvider } from \"firebase/auth\";\n\n const auth = getAuth();\n signInWithPopup(auth, provider)\n .then((result) =\u003e {\n // User is signed in.\n // IdP data available using getAdditionalUserInfo(result)\n\n // Get the OAuth access token and ID Token\n const credential = OAuthProvider.credentialFromResult(result);\n const accessToken = credential.accessToken;\n const idToken = credential.idToken;\n })\n .catch((error) =\u003e {\n // Handle error.\n });\n\n Web \n\n firebase.auth().signInWithPopup(provider)\n .then((result) =\u003e {\n // IdP data available in result.additionalUserInfo.profile.\n // ...\n\n /** @type {firebase.auth.OAuthCredential} */\n var credential = result.credential;\n\n // OAuth access and id tokens can also be retrieved:\n var accessToken = credential.accessToken;\n var idToken = credential.idToken;\n })\n .catch((error) =\u003e {\n // Handle error.\n });\n\n5. While the above examples focus on sign-in flows, you can use the same\n pattern to link an OIDC provider to an existing user using\n `linkWithRedirect()` and `linkWithPopup()`, and re-authenticate a user with\n `reauthenticateWithRedirect()` and `reauthenticateWithPopup()`, which can be\n used to retrieve fresh credentials for sensitive operations that require\n recent login.\n\nHandle the sign-in flow manually\n\nIf you've already implemented the OpenID Connect sign-in flow in your app, you\ncan use the ID token directly to authenticate with Firebase: \n\nWeb \n\n import { getAuth, signInWithCredential, OAuthProvider } from \"firebase/auth\";\n\n const provider = new OAuthProvider(\"oidc.example-provider\");\n const credential = provider.credential({\n idToken: idToken,\n });\n signInWithCredential(getAuth(), credential)\n .then((result) =\u003e {\n // User is signed in.\n // IdP data available in result.additionalUserInfo.profile.\n\n // Get the OAuth access token and ID Token\n const credential = OAuthProvider.credentialFromResult(result);\n const accessToken = credential.accessToken;\n const idToken = credential.idToken;\n })\n .catch((error) =\u003e {\n // Handle error.\n });\n\nWeb \n\n const provider = new OAuthProvider(\"oidc.example-provider\");\n const credential = provider.credential({\n idToken: idToken,\n });\n firebase.auth().signInWithCredential(credential)\n .then((result) =\u003e {\n // User is signed in.\n // IdP data available in result.additionalUserInfo.profile.\n\n // Get the OAuth access token and ID Token\n const credential = OAuthProvider.credentialFromResult(result);\n const accessToken = credential.accessToken;\n const idToken = credential.idToken;\n })\n .catch((error) =\u003e {\n // Handle error.\n });"]]