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

122
Visualizações
How redirect oauth2 authentification to frontend instead of redirecting in the backend using passport?

I use Vue and Node and passport for authentication with local and oauth2 (passport-github) strategies.

My local strategy works but I have problems with my oauth2.

I have a 'login with github' button in my login page, when clicking it will make an axios request to my backend (http://localhost:3000/auth/github).

const api = axios.create({
    baseURL: 'http://localhost:3000/',
    withCredentials: true,
    timeout: 1000,
});

async function APIloginWithGitHub() {
    const response = await api.get('/auth/github')
    return response.data
}
router.get('/github', passport.authenticate('github'))

router.get('/auth/github/callback', 
  passport.authenticate('github'),
  function(req, res) {
    res.send('You have been successfully authenticated!');
  });

At the middleware level of my backend, I use this strategy configuration:

const GitHubStrategy = require('passport-github').Strategy;
const User = require('../models/User')

module.exports = function (passport) {
  passport.use(new GitHubStrategy({
    clientID: process.env.GITHUB_APP_ID,
    clientSecret: process.env.GITHUB_APP_SECRET,
    callbackURL: "http://localhost:3000/auth/github/callback"
  },
    async (token, tokenSecret, profile, done) => {
      console.log(profile)
    }
  ));
};

This will redirect to the github authentication page on the backend and involve issues

about 4 years ago · Juan Pablo Isaza
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