1

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

Faulheit
  • 116
  • 7
  • Does this answer your question? [Access to fetch at https://accounts.google.com/o/oauth2/v2/auth has been blocked by CORS](https://stackoverflow.com/questions/72382892/access-to-fetch-at-https-accounts-google-com-o-oauth2-v2-auth-has-been-blocked) It seems that you trying to launch a logon flow via `axios.get` whereas it must happen in a visible browsing context. – Heiko Theißen Mar 04 '23 at 08:46
  • @HeikoTheißen maybe, I don't remember what was this project. This question resurfaced because stack overflow asks me to fix my questions to ask new questions. – Faulheit Mar 04 '23 at 08:53

0 Answers0