【发布时间】:2020-07-28 02:56:20
【问题描述】:
我对 Google OAUth2.0 身份验证非常陌生,因此我的问题听起来很愚蠢。但是,我被这个问题困扰了很长时间,需要您的意见来解决它。
我在 my app 中集成了 Globus 登录。 Globus 登录使用 Google OAuth-2 协议进行身份验证。根据Globus Auth developer guide,我成功将应用重定向到他们的授权服务,用户可以将他们的凭据进行身份验证,并且应用在成功验证后接收从Globus Auth服务器返回的代码。下一步是将代码发送到 Token 端点以获取访问令牌。我使用了以下代码:
var querystring = require('querystring');
export const logInGlobus = (payload) => {
let tokenUri = encodeURIComponent(payload.redirect_uri);
let client_id = 'out app client id'
let client_secret = 'client secret generated for authentication'
let cred = btoa(client_secret);
return axios.post('https://auth.globus.org/v2/oauth2/token',
querystring.stringify({
grant_type: 'authorization_code',
code: payload.code,
redirect_uri: tokenUri,
client_id: client_id
}),
{
headers:{
Authorization: 'Basic '+ cred,
'Content-Type': 'application/x-www-form-urlencoded'
}
})
.then(response => {
return{
res: response,
success: true
}
})
.catch(err => {
return{
res: err,
success: false
}
})
}
我收到来自服务器的此发布请求的 401 {"error":"invalid_client"} 代码。我错过了什么?
N.B:我尝试过不使用客户端密码、客户端 ID、不编码重定向 URL。到目前为止没有运气>
如果您能给我一些启发,我将非常感谢您的努力。感谢您的宝贵时间。
====编辑====
附加浏览器控制台的错误
【问题讨论】:
-
能否附上具体错误的截图
-
附加了来自控制台的错误。您可以通过在 p2irc-data-dev.usask.ca 上单击我的应用程序窗口顶部的登录按钮,然后单击 Globus 登录并在 Globus 执行身份验证来重现该错误。
标签: javascript oauth-2.0 axios google-oauth http-status-code-401