jaredhanson / jaredhanson/passport-github
TokenError: The client_id and/or client_secret passed are incorrect.
- Dominant language
- JavaScript
- Stars
- 535
- Forks
- 290
- PR merge metrics
- No merged PRs in 30d
Description
I write app demo just like the example code:
```javascript
passport.use(new GitHubStrategy({
clientID: process.env.GITHUB_CLIENT_ID as string,
clientSecret: process.env.GITHUB_CLIENT_SECRET as string,
callbackURL: "http://127.0.0.1:3000/auth/github/callback"
},
function(accessToken, refreshToken, profile, callback) {
return callback(null, {});
}
));
passport.serializeUser((user, done) => {
console.log('serializeUser');
done(null, 1);
});
passport.deserializeUser((id, done) => {
console.log('deserializeUser');
done(null, {});
});
// app.use(helmet());
// app.use(cors());
app.use(express.json());
app.use(session({
store: new MemoryStore({
checkPeriod: 86400000 // prune expired entries every 24h
}),
secret: process.env.SESSION_SECRECT as string,
resave: false,
saveUninitialized: false,
cookie: {
secure: true,
httpOnly: true,
}
}));
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(passport.initialize());
app.use(passport.session());
app.get('/auth/github',
passport.authenticate('github'));
app.get('/auth/github/callback',
passport.authenticate('github', { failureRedirect: '/login_failed' }),
function(req, res) {
res.redirect('/');
});
```
however, when I try to login, I get the error:
```
TokenError: The client_id and/or client_secret passed are incorrect.
at Strategy.OAuth2Strategy.parseErrorResponse (/Users/guangyi.li/Desktop/side-project/tenet/node_modules/passport-oauth2/lib/strategy.js:358:12)
at Strategy.OAuth2Strategy._createOAuthError (/Users/guangyi.li/Desktop/side-project/tenet/node_modules/passport-oauth2/lib/strategy.js:405:16)
at /Users/guangyi.li/Desktop/side-project/tenet/node_modules/passport-oauth2/lib/strategy.js:175:45
at /Users/guangyi.li/Desktop/side-project/tenet/node_modules/passport-github/lib/strategy.js:79:16
at /Users/guangyi.li/Desktop/side-project/tenet/node_modules/oauth/lib/oauth2.js:209:7
at passBackControl (/Users/guangyi.li/Desktop/side-project/tenet/node_modules/oauth/lib/oauth2.js:134:9)
at IncomingMessage. (/Users/guangyi.li/Desktop/side-project/tenet/node_modules/oauth/lib/oauth2.js:157:7)
at IncomingMessage.emit (events.js:327:22)
at IncomingMessage.EventEmitter.emit (domain.js:482:12)
at endReadableNT (_stream_readable.js:1221:12)
```
It seem the issue happened here, the returned access token is undefined:

but I found my github oauth already have one user, and the user also have the oauth app authorized. So what's wrong with my code ?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at the /auth/github route and its /auth/github/callback handler, then verify the GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET values against the configured GitHub OAuth app. Done means the callback completes without the TokenError and the strategy receives an access token.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- authentication
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100