Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

278
Views
How to save token after successful oidc authentication using oidc-client in JavaScript?

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.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You should use UserManager as in this code of mine.

  • Calls signInRedirectCallback
  • Shows how to continue afterwards, eg update UI state

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.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!