Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

280
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda