oidc-client-ts
oidc-client-ts copied to clipboard
Serialize a UserManager instance
Hello here !
First of all, thanks for the library :)
I have a question about the UserManager instance. Is this possible to serialize and deserialize an UserManager instance ? It seems that JSON.stringify(userManager) throws an error.
My use case is mobile oriented by using Biometrics. I am trying to "store" a user manager instance, or at least the data needed to get new access token like refreshToken (and try to create a new UserManager with those data, but the constructor does not expose data to do so).
Any idea about the subject ?
Best regards, A.
You can store and restore the user data object (incl. access token, ...) anywhere you want.
With settings like
userStore: new WebStorageStateStore({ store: window.localStorage }),
Thank you so much, @pamapa, for your detailed response!
If I understand the process correctly, in the case where I'm using secure storage (especially on mobile, with Capacitor for example), I can create a custom WebStorageStateStore with a custom store that implements AsyncStorage. By using this approach, at each change event such as SigninRedirectCallback or token refresh, the userManager.storeUser method will allow me to save a serialized version of the user manager configuration into my secure storage (or should I trigger the userManager.storeUser() myself ?)
However, to avoid going through a redirection to my Identity Provider's page and for a smoother user experience, I can trigger userManager.getUser at the application start, which will directly fetch from my secure local storage, thus allowing me to retrieve the information without going through the redirection to the authentication page and then redirect to my protected pages.
Is that correct?
Thanks a lot. A.
If you need guidance on how to make it work with Capacitor you can have a look here: https://github.com/authts/oidc-client-ts/issues/537#issuecomment-1406247758