gpt4 book ai didi

node.js - grant_type=password 上未定义 client_id (oauth2orize)

转载 作者:太空宇宙 更新时间:2023-11-04 02:31:33 25 4
gpt4 key购买 nike

我正在使用oauth2orize和passport在nodejs中创建一个API,但是当我请求 token 时,client_id参数未定义。

Oauth2orize:

server.exchange(oauth2orize.exchange.password(function (client, username, password, scope, callback) {
console.log(client); // This is undefined

帖子:

grant_type: password,
client: id_client, // I tried with client_id, clientId, id...
username: username,
password: password

为什么客户端参数未定义?

非常感谢

最佳答案

您需要创建至少一个如下所示的护照策略:

var passport = require('passport'),
ClientPasswordStrategy = require('passport-oauth2-client-password').Strategy ;

passport.use("clientPassword", new ClientPasswordStrategy(
function (clientId, clientSecret, done) {
Clients.findOne({clientId: clientId}, function (err, client) {
if (err) return done(err)
if (!client) return done(null, false)
if (!client.trustedClient) return done(null, false)

if (client.clientSecret == clientSecret) return done(null, client)
else return done(null, false)
});
}
));

然后您需要绑定(bind)您的路线,以便您的请求能够通过抛出此策略:(带有express)

app.post('/url', passport.authenticate('clientPassword'), server.token());

最后,要请求您的 token ,POST 参数必须是:

  • client_id
  • client_secret
  • 用户名
  • 密码
  • grant_type:密码

关于node.js - grant_type=password 上未定义 client_id (oauth2orize),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26302356/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com