If you use Firebase Authentication to authenticate your users, you can use the same authentication to log users into Xkit to connect other apps to yours.
To set up Firebase Authentication with Xkit, use the following steps:
- Click on Settings in the left sidebar and scroll down to "User Tokens"
- Click "Add Custom Issuer"
- For the "
iss
Claim", use the valuehttps://securetoken.google.com/<projectId>
where<projectId>
is your Firebase project ID, the unique identifier for your Firebase project, which can be found in the URL of that project's console. - For the "
aud
Claim", use the value<projectId>
as defined in #3. - For the "User ID Claim", keep it as
sub
. - Optionally For the "Friendly User Name Claim", use the value
email
- For the "JSON Web Key Set URL", use the value
https://www.googleapis.com/service_accounts/v1/jwk/[email protected]
- Click "Save"
Your Xkit installation will now be able to use your Firebase ID tokens to login to Xkit.
An example usage is below:
import firebase from "firebase/app"
import "firebase/auth"
const config = {
apiKey: <your API key>,
authDomain: <your domain>,
};
firebase.initializeApp(config);
firebase.auth().onAuthStateChanged(async (user) => {
if (user) {
const token = await user.getIdToken()
await window.xkit.login(token)
} else {
await window.xkit.logout()
});
User Groups
If you want to use the User Groups feature, you'll need to add a custom claim to your Firebase token and add that claim to your issuer settings under Group ID claim
.
Further Reading
For more details about this process, check out the Custom Token Issuer Guide on Xkit and the Verify ID Tokens documentation on Firebase.
Updated 25 days ago