Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 9751c7f

Browse files
#1145 Added option to retrieve Firebase custom claims
1 parent 742fe5b commit 9751c7f

File tree

1 file changed

+4
-27
lines changed

1 file changed

+4
-27
lines changed

docs/AUTHENTICATION.md

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -646,43 +646,20 @@ To solve, you will want to pass in the appropriate iOS controller of the active
646646
3. Those fingerprints need to be added to your Firebase console. Go to 'project overview', 'project settings', then scroll down a bit.
647647

648648
### getAuthToken
649-
If you want to authenticate your user from your backend server you can obtain
650-
a Firebase auth token for the currently logged in user.
649+
If you want to authenticate your user from your backend server you can obtain a Firebase auth token for the currently logged in user.
651650

652-
You can choose to get just the token itself or the token plus any custom claims you may have previously set via the Firebase Admin SDK as outlined [here](https://firebase.google.com/docs/auth/admin/custom-claims):
653-
654-
Just token:
651+
You'll get the token, as well as the provider that was used to sign in, and any custom claims you may have previously set via the Firebase Admin SDK as outlined [here](https://firebase.google.com/docs/auth/admin/custom-claims):
655652

656653
```js
657654
firebase.getAuthToken({
658655
// default false, not recommended to set to true by Firebase but exposed for {N} devs nonetheless :)
659656
forceRefresh: false
660-
}).then(
661-
function (token) {
662-
console.log("Auth token retrieved: " + token);
663-
},
664-
function (errorMessage) {
665-
console.log("Auth token retrieval error: " + errorMessage);
666-
}
667-
);
668-
```
669-
670-
Token with custom claims:
671-
672-
```js
673-
firebase.getAuthToken({
674-
// default false, not recommended to set to true by Firebase but exposed for {N} devs nonetheless :)
675-
forceRefresh: false,
676-
// set to true to also retrieve your custom claims
677-
withClaims: true
678657
}).then(
679658
function (result) {
680659
// for both platforms
681660
console.log("Auth token retrieved: " + result.token);
682-
// Android only
683-
console.log("Specific custom claim retrieved: " + result.claims.get('yourClaimKey'));
684-
// iOS only
685-
console.log("Specific custom claim retrieved: " + result.claims.objectForKey('yourClaimKey'));
661+
console.log("Sign-In provider: " + result.signInProvider);
662+
console.log("Specific custom claim retrieved: " + result.claims.yourClaimKey); // or result.claims["yourClaimKey"]
686663
},
687664
function (errorMessage) {
688665
console.log("Auth result retrieval error: " + errorMessage);

0 commit comments

Comments
 (0)