I've got a .NET based mobile app. It uses .NET MAUI but not sure if it is relevant. I am using FirebaseAuthentication.net Nuget library, but happy to do my own http requests.
At sign in or sign up I am doing following calls
var userCredential = await client.CreateUserWithEmailAndPasswordAsync("email", "pwd", "Display Name");
var userCredential = await client.SignInWithEmailAndPasswordAsync("email", "pwd");
Both functions successfully return a UserCredential object which contains both the Id Token and Refresh Token amongst other things.
I'd like to have the user signed in even after completely exiting the app and reopening it. My understanding is that the Id Token is short lived and it needs to be renewed using the Refresh Token which practically lasts for the life time of the user account.
However, there doesn't seem to be a direct method that takes Refresh Token as parameter and returns the Id Token. One needs to call:
userCredential.User.GetIdTokenAsync()
To either get the exiting token or the refreshed one if it has expired.
Since UserCredential is a relatively complex object, I don't think I will be able to store the refresh token and repopulate this object the next time the app is started.
One alternative I can think of is to serialise userCredential object and save it. But this sounds more like a hack.
I suppose I can store the user's password, and sign in in the background every time, but that is likely to defy the purpose of using tokens.
Is there a better way to stay signed in across sessions ?