错误:invalid_request缺少必需的参数:范围(带有Google OAuth2的Restify和Passportjs)

布兰农厅

因此,使用Restify和Passportjs(Google OAuth2策略)时,我的Node.js应用遇到了问题。使用时passport.authenticate(),出现以下错误:

400.那是一个错误。
错误:invalid_request
缺少必需的参数:范围

我发现了几年前关于同一件事的另一个问题(invalid_request缺少:在Google Oauth2上使用Google Passportjs的作用域)。作者说他终于自己修复了,但没有发布修复程序。

还有其他人遇到这个问题并能够解决吗?我不知道。这是我的代码:

authController.js

var passport = require('passport');
var GoogleStrategy = require('passport-google-oauth20').Strategy;

var auth = {
  google: {
    clientID: '<ID>',
    clientSecret: '<SECRET>',
    callbackURL: 'https://localhost:8080/auth/google/return',
    scope: ['profile', 'email']
  }
};

passport.use(new GoogleStrategy({
    clientID: auth.google.clientID,
    clientSecret: auth.google.clientSecret,
    callbackURL: auth.google.callbackURL
}, function(accessToken, refreshToken, profile, cb) {
  return cb(null, profile.id);
}));

module.exports.authenticate = passport.authenticate('google', { scope: auth.google.scope });
module.exports.isAuthenticated = passport.authenticate('google', { successRedirect: '/hello/succeed', failureRedirect: '/hello/fail' });

server.js

var restify = require('restify'),
    fs = require('fs'),
    bodyParser = require('body-parser'),
    authController = require('./controllers/authController');

// Placeholder handler.
function respond(req, res, next) {
  res.send('hello ' + req.params.name);
  return next();
}

// Create server.
var api = restify.createServer({
  certificate: fs.readFileSync('server.crt'),
  key: fs.readFileSync('server.key'),
  name: 'BQ:IQ Question Writer'
});

// Setup authentication
api.get('/auth/google', authController.authenticate);
api.get('/auth/google/return', authController.isAuthenticated);

// Setup routes.
api.get('/hello/:name', respond);
api.head('/hello/:name', respond);

api.listen(8080, function() {
  console.log('%s listening at %s', api.name, api.url);
});
布兰农厅

初始化服务器后,似乎缺少以下代码:

api.use(restify.plugins.queryParser({ mapParams: false }));

添加该行后,我再也看不到Google错误,该过程又传回了我的代码。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Devise和Omniauth-soundcloud错误-invalid_request:缺少必需的参数:client_id

如何使用OAuth2和PassportJS获取Google Fitness API数据

尝试在 Graphql-Yoga Server 中使用 Google Oauth2 和 Passportjs

Oauth2 YouTube“错误”:“ invalid_request”

gosimple / oauth2和Google OAuth2

Google OAuth2:缺少必需的参数:grant_type

Google身份验证错误:invalid_request缺少必需的参数:client_id

Oauth2,范围和用户角色

oauth令牌请求错误,带有“缺少必需的参数'client_id'”,

Google Analytics(分析)API:如何解决OAuth2缺少范围参数错误?

错误:invalid_request缺少必需的参数:golang中的client_id

带有 angular-oauth2-oidc 的 OAuth2 和 SSO 不会检索访问令牌

Unity 和 Google OAuth2 授权代码流

Oauth2授予类型和良好文档的实时示例,带有Spring MVC的Oauth2的示例

具有JWT和OAuth2的JHipster

带有devise和omniauth的Google oauth2被视为失败

Google OAuth2 API

错误:缺少 2 个必需的位置参数

Google OAuth2:错误401-invalid_client

带有gard的Symfony Oauth2

带有Spring OAuth2的JWT

Firebase-NodeJS:带有OAuth2的Google API的域范围委派

带有Client_Id和Client_Secret的OAuth2密码授予类型

带有spring和jwt的OAUTH2服务器

使用oauth2和Google API无法识别的参数

<lambda>()缺少1个必需的位置参数:带有lambda和reduce的'z'

如何配置Spring Boot和Spring Security以支持表单登录和Google OAuth2登录

带有刷新令牌的春季Google OAuth2

带有节点js的Google oauth2