Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

287
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda