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