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

189
Visualizações
Using Google Oauth in FeathersJs with an existing access token

How do I use the Google Oauth in featherjs with an existing access token? The docs do not give an example on this. The only example is through the browser as shown here.

When going through the browser, http://localhost:3030/oauth/google works ok. I can successfully add the user to my DB. Here is my code:

const { LocalStrategy } = require("@feathersjs/authentication-local");
const { expressOauth } = require("@feathersjs/authentication-oauth");
const { OAuthStrategy } = require("@feathersjs/authentication-oauth");
var uniqid = require("uniqid");
const { AuthenticationService, JWTStrategy } = require('@feathersjs/authentication');        

class GoogleStrategy extends OAuthStrategy {
  async getEntityData(profile) {
    const baseData = await super.getEntityData(profile);
    console.log({ profile });

    return {
      ...baseData,
      profilePicture: profile.picture,
      email: profile.email,
      password: uniqid.time(),
    };
  }
}

module.exports = (app) => {
const authentication = new AuthenticationService(app);        
authentication.register("local", new LocalStrategy());
authentication.register('jwt', new JWTStrategy());
authentication.register("google", new GoogleStrategy());

  app.use("/authentication", authentication);
  app.configure(expressOauth());
};

However if I try using an access token,like so

POST http://localhost:3030/authentication
data: {
    "strategy": "google",
    "accessToken": "ya29.A0ARrdaM_UJa6idfZr-4taqwkJ6qGBV1Dp9wbxF-wsult8dNPaVNCVg6Fndmrqv7BhRSwxa5gAKllPvbKtsjyxS39WdmWmqkmE42HOsVZaJWHVEttxbebel3zdpD5BSxWtRiG7NuZLNVedMUaK5AdgIRrJk1u"
}

I do not get the google profile, no user is added to my DB and I get this error:

{
  "name": "GeneralError",
  "message": "401 Unauthorized",
  "code": 500,
  "className": "general-error",
  "data": {},
  "errors": {}
}

I have added "google" to my list of authStrategies in default.json

So my question is what do I need to do?

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

0

So I found the solution. Thought I might share. Add this to authentication.js

 //add this method
 async getProfile(authResult) {
    const accessToken = authResult.accessToken;

    const { data } = await axios
      .get(
        `https://openidconnect.googleapis.com/v1/userinfo?access_token=${accessToken}`
      )
      .then((res) => {
        return res;
      })
      .catch((error) => console.log("autherr", error));

    return data;
}
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