Hello i am trying to retrieve id_token after successful authentication using oidc and oidc-client library. Below you can inspect my service definition:
import Oidc from "oidc-client";
const config = {
authority: process.env.VUE_APP_API_URL,
client_id: process.env.VUE_APP_OAUTH_CLIENT_ID,
redirect_uri: process.env.VUE_APP_OAUTH_REDIRECTION_URL,
response_type: process.env.VUE_APP_OAUTH_RESPONSE_TYPE,
scope: process.env.VUE_APP_OAUTH_SCOPE,
post_logout_redirect_uri: process.env.VUE_APP_OAUTH_REDIRECTION_URL
};
const userManager = new Oidc.UserManager(config);
const service = {
signIn() {
userManager.signinRedirect();
},
signOut() {
userManager.signoutRedirect();
},
};
export default service;
After authentication process, im being redirected from Google to this url:
http://localhost:8080/#id_token=mytoken&scope=openid&state=mystate&session_state=mysessionstate
I would like to persist the retrieved token in the local storage. My first concern is to know from which place should i get token. I can get it directly from the url, or maybe use Oidc.UserManager. Intuition says that i should get it from userManager, but i am curious what are the pros/cons of two solutions. The second question is how i can catch a hook which is triggered after redirection? I mean i want to run some logic if the redirection is 100% completed. I tried to use "await", and "then" function however signinRedirect seems to be finished before redirection completes. I know there is some function called signinRedirectCallback, however don't know how to use it to be 100% sure it's running after redirection completion. Thanks in advance for any help. Regards.
You should use UserManager as in this code of mine.
A key point to understand is that you need to check for OIDC responses whenever the SPA loads. But only actually call signInRedirectCallback when you detect that you have one.
I believe local storage is used by default, but there are options to override this as in this other configuration.