I’m using Firebase Auth in my app and I’m signing in using an OAuthProvider like this:
final credential = await FirebaseAuth.instance.signInWithProvider(
OAuthProvider('oidc.my-oidc-provider')
..setScopes([
'openid',
'profile',
'email',
'offline_access',
// Some more custom scopes
]),
);
I can get the access token issued by the OIDC provider from the credential like this:
final accessToken = credential.credential?.accessToken;
and store it in some provider (I’m using Riverpod) to use it later to authenticate requests to my backend.
However, I’m wondering how I should handle refreshes in this case. I don’t see a way to get this access token again from the user
callback parameter of methods such as authStateChanges
, idTokenChanges
or userChanges
.
I have found the reauthenticateWithProvider
method on user
, which does give me the credential again but I’m not sure if I should be using it in this case.
Some guidance on how to keep the access token up to date would be greatly appreciated!
PS: I’ve noticed that when I call the signOut
method on the FirebaseAuth instance, the user is not actually signed out of my OIDC provider. The next time I sign in, the username/password prompt is skipped, suggesting that the user was still signed in.
I’m not sure if these issues are related to each other. If not I will make a separate question.