firebase / firebase/firebase-js-sdk
Auth: provide custom nonce on sign in
- Dominant language
- TypeScript
- Stars
- 5.1k
- Forks
- 1k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 37
Description
### Operating System
macos
### Environment (if applicable)
chrome 131.0.6778.86
### Firebase SDK Version
11.0.2
### Firebase SDK Product(s)
Auth
### Project Tooling
react app with vite
### Detailed Problem Description
When using the Twitter provider for login, we receive a JWT token. However, the payload of this JWT token does not include a `nonce` by default. We would like the JWT token issued by Firebase to include a custom `nonce` that we provide. Currently, we cannot find a way to supply this `nonce`. Is there any method to achieve this?
### Steps and code to reproduce issue
We want to provide our custom nonce in `signInWithTwitter` function.
```typescript
import { initializeApp } from 'firebase/app';
import { getAuth, TwitterAuthProvider, signInWithPopup } from 'firebase/auth';
const firebaseConfig = {...firebaseConfig};
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
const twitterProvider = new TwitterAuthProvider();
export const signInWithTwitter = () => {
// we want to provide custom nonce here
signInWithPopup(auth, twitterProvider)
.then((result) => {
const credential = TwitterAuthProvider.credentialFromResult(result);
console.log('credential', credential);
const token = credential?.accessToken;
const secret = credential?.secret;
// ...
// The signed-in user info.
const user = result.user;
console.log('token', token);
console.log('secret', secret);
console.log('user', user);
console.log('credential', credential);
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
// The email of the user's account used.
const email = error.customData.email;
// The AuthCredential type that was used.
const credential = TwitterAuthProvider.credentialFromError(error);
console.log(errorCode, errorMessage, email, credential);
});
};
```
Contributor guide
Assessment
This issue has not been assessed yet.