eggjs / eggjs/egg

egg-passport使用passport-oauth2策略不能保存认证状态,一直会重复认证

Open
#1,380 9 comments 0 reactions 1 assignee Claimed by @fengmk2 View on GitHub
Inactive not follow template plugin: egg-passport
Dominant language
TypeScript
Stars
19k
Forks
1.8k
PR merge metrics
No merged PRs in 30d

Description

加上passport-oauth2后会一直重复认证..
**代码:**
```
// app/config/plugin.js
exports.passport = {
enable: true,
package: 'egg-passport',
};

```

```
// app.js
const OAuth2Strategy = require('passport-oauth2').Strategy;

module.exports = app => {

app.passport.use('oauth2',new OAuth2Strategy({
authorizationURL: app.config.passportYun9.authorizationURL,
tokenURL: app.config.passportYun9.tokenURL,
clientID: app.config.passportYun9.clientID,
clientSecret: app.config.passportYun9.clientSecret,
callbackURL: app.config.passportYun9.callbackURL,
passReqToCallback:true
},
function(req,accessToken, refreshToken, profile, done) {
const user = {
accessToken:accessToken,
refreshToken:refreshToken
};
console.log('doVerify');
app.passport.doVerify(req, user, done);
}
));
};
```

```
// app/router.js
app.get('/',app.passport.authenticate('oauth2'), 'home.index');
app.get('/auth/callback',app.passport.authenticate('oauth2',{
successRedirect: '/home',
failureRedirect: '/login'
}), 'home.index');
app.get('/home', app.passport.authenticate('oauth2'), 'home.index');
```
像这样在‘/home’中添加认证中间件就会一直重复认证,想知道是思路不对还是需要重写一个oauth2的认证插件?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.