首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >client_id未定义于grant_type=password (oauth2orize)

client_id未定义于grant_type=password (oauth2orize)
EN

Stack Overflow用户
提问于 2014-10-10 14:59:38
回答 1查看 1.4K关注 0票数 1

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

Oauth2orize:

代码语言:javascript
复制
server.exchange(oauth2orize.exchange.password(function (client, username, password, scope, callback) {
    console.log(client);    // This is undefined

员额:

代码语言:javascript
复制
grant_type: password,
client: id_client,    // I tried with client_id, clientId, id...
username: username,
password: password

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

非常感谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-03 13:34:31

您需要创建至少一个这样的护照策略:

代码语言:javascript
复制
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)
        });
    }
));

然后,您需要绑定您的路由,以便您的请求将通过抛出的策略:(与快件)

代码语言:javascript
复制
app.post('/url', passport.authenticate('clientPassword'), server.token());

最后,要请求令牌,POST参数必须是:

  • client_id
  • client_secret
  • 用户名
  • 密码
  • grant_type :密码
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26302356

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档