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

248
Visualizações
How to get access token with refresh token for YouTube Data API through Firebase Google authentication?

I wanted to build a web app that can view the user's YouTube channel info. I used Firebase for authentication with Google and then stored the accessToken and refreshToken with the help of the code below.

const provider = new GoogleAuthProvider();

    provider.addScope("https://www.googleapis.com/auth/youtube.readonly");

    signInWithPopup(auth, provider)
      .then(async (result) => {
        // This gives you a Google Access Token. You can use it to access the Google API.
        const credential = GoogleAuthProvider.credentialFromResult(result);

        const accessToken = credential.accessToken;
        const refreshToken = result._tokenResponse.refreshToken;
        const user = result.user;
        localStorage.setItem("accessToken", accessToken);
        localStorage.setItem("refreshToken", refreshToken);
        localStorage.setItem("user", user);
}

But after the expiry of the accessToken, it gets invalid. So, I want to get the newly created accessToken with help of refreshToken but I could not find any way to retrieve that.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Firebase SDKs don't manage provider tokens as mentioned in this answer. Easiest way would be to reauthenticate the user but users may have to re-authorize your application if needed. Re-authenticating will return same UserCredential object as result in code snippet in your question.

Another option would be to use provider's own SDK and refreshing the token whenever required.

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