我正在使用Node.Js,Express,passport和Passport-oauth2开发一些简单的API端点。
我能够使用passport-oauth2生成令牌,并使用它来设置重定向的标头。
app.get('/auth/example',passport.authenticate('oauth2'),
(req, res) => {res.send("Hello example.")}
);
app.get('/auth/example/redirect', (req, res) => {
console.log("accessToken is " + req.query.code) ;
res.setHeader('Authorization', 'Bearer ' + req.query.code);
res.redirect(301, 'https://somepublicAPIendpoint');
});
它被重定向到http:// somepublicAPIendpoint;但是我收到一条错误消息,指出它是Invalid access token
。
我尝试通过两种方式通过邮递员调用https:// somepublicAPIendpoint。
Invalid access token
。令牌代码约为50个字符。我了解护照-oauth2令牌生成无法按预期方式工作。这是我使用的策略。
passport.use(new OAuth2Strategy({
authorizationURL: 'https://zoom.us/oauth/authorize',
tokenURL: 'https://api.zoom.us/oauth/token',
clientID: 'clientId',
clientSecret: 'secretId',
callbackURL: "http://myapp/auth/example/redirect"
},
(accessToken, refreshToken, profile, done) => {console.log("callback function invoked.") ;}
));
如何纠正此问题?
答案 0 :(得分:0)
您需要添加您请求访问的范围。示例
passport.authenticate('oauth2', {scope: ['user_profile', 'user:read', 'user:read:admin']})