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

180
Views
Uso de Google Oauth en FeathersJs con un token de acceso existente

¿Cómo uso Google Oauth en featherjs con un token de acceso existente? Los documentos no dan un ejemplo sobre esto. El único ejemplo es a través del navegador como se muestra aquí .

Al pasar por el navegador, http://localhost:3030/oauth/google funciona bien. Puedo agregar con éxito al usuario a mi base de datos. Aquí está mi código:

 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()); };

Sin embargo, si trato de usar un token de acceso, así

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

No me sale el perfil de google, no se agrega ningún usuario a mi base de datos y me sale este error:

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

He agregado "google" a mi lista de authStrategies en default.json

Entonces mi pregunta es ¿qué debo hacer?

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

0

Así que encontré la solución. Pensé que podría compartir. Agregue esto a autenticación.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 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!