firebase.auth.Auth.onIdTokenChanged should return accessToken
See original GitHub issueFor applications requiring the accessToken from a provider to make further API requests to said provider (for example, making requests to various Google APIs), they can fetch the initial access token via getRedirectResult()
or signInWithPopup()
, since these both pass firebase.auth.UserCredential
.
However, when an access token is periodically refreshed, there’s no means to get a corresponding firebase.auth.UserCredential
.
It seems as though since onIdTokenChanged
is triggered for token refreshes where as onAuthStateChanged
is not, that onIdTokenChanged
should pass a firebase.auth.UserCredential
instead of firebase.User
.
Is there any other means to listen for changes to the accessToken
upon refresh?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:6
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Auth | JavaScript SDK | Firebase JavaScript API reference
Reference for Auth. ... Indicates that the state will be persisted even when the browser window is closed or the activity is destroyed...
Read more >reactjs - How can I request a new access token after the ...
We do have a method like onAuthStateChanged auth.onIdTokenChanged(async (user) => { const token = await user?.getIdToken(); localStorage.
Read more >Firebase Auth Refresh Token? - Reddit
The token returned from the login function that can be used to access Google API ( const token = credential.accessToken) returns ya29.a0ARrdaM- ...
Read more >Authenticated server-side rendering with Next.js and Firebase
User | null>(null); useEffect(() => { return firebase.auth().onIdTokenChanged(async (user) ...
Read more >Next.js: Firebase Authentication and Middleware for API Routes
Building Next.js app with Firebase authentication on the ... We definitely need to return something from getAuth and that'll be the auth ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks @bojeil-google! Makes sense when you consider that design decision. I do think that it this feature request should be considered for firebase auth since I doubt that I’m the only one who wants to use a Google API with the access token granted.
That said, even if this doesn’t land in firebase anytime soon, I think what would be immensely helpful is a full example of how to use GAPI to auth and pass those credentials to firebase. I plan to write up an example on this soon and will post it to this thread for others to have a look at.
The underlying Firebase Auth SDK does not manage OAuth credentials. After the sign-in operation, they discard your OAuth credentials, including the OAuth refresh tokens. The primary goal of Firebase Auth is AuthN and not AuthZ.
onIdTokenChanged
listener is used to detect Firebase Auth ID token changes and has nothing to do with the underlying authentication provider.If you think Firebase Auth should manage OAuth tokens, please file a feature request via Firebase Support channels and explain why you think this is a critical functionality that Firebase Auth should support.
If getting a Google OAuth token is a requirement for your application, you should consider using the Google Sign in library for web which manages OAuth token refresh . Using that, you can sign in with Firebase Auth too but this is not compatible with FirebaseUI.