【问题标题】:client_id undefinded on grant_type=password (oauth2orize)在 grant_type=password (oauth2orize) 上未定义 client_id
【发布时间】:2014-12-05 19:07:03
【问题描述】:

我正在使用 oauth2orize 和护照在 nodejs 中创建一个 API,但是当我请求令牌时,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

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

非常感谢

【问题讨论】:

    标签: node.js oauth2orize


    【解决方案1】:

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

    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)
            });
        }
    ));
    

    然后你需要绑定你的路由,这样你的请求才会通过 throw this Strategy : (with express)

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-16
      • 2019-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-08
      • 2012-06-09
      • 2016-04-22
      相关资源
      最近更新 更多