我有一个用Ruby编写的后端API和一个使用Angular的客户端应用程序。我想验证用户身份,以通过Angular应用程序验证用户身份。因此,我已经在Asana上创建了我的App。我有几个问题:第一个问题:我正在使用Authorisation Code Grant的授权端点。阅读文档后,我意识到我必须改用Implicit Grant,它更适合基于浏览器的应用程序,但是当我将其更改为Implicit Grant,保存并重新加载页面后,它又变回。然后在我的Angular应用中,我有以下代码: var client = Asana.Client.create({ clientId: 133, clientSecret: 'mysecretcode', redirectUri: 'http://localhost:7699/profile' }); client.useOauth({ flowType: Asana.auth.PopFlow }); client.authorize().then(function () { console.log('Auth completed'); }).catch(function (err) { console.log(err); }); client.users.me().then(function (result) { console.log(result); });以上几乎有效。我确实被重定向到Asana的授权部分,一旦我单击“允许”,我就被重定向回我的应用程序,并且确实获得了作为URL一部分的代码。代码类似于:http://localhost:7699/profile#access_token=very_long_string如果我正确理解了文档,则可以使用上面的Authorisation Code Grant发出第一个请求。当我尝试使用Asana的JS库发出这样的请求时:client.users.me().then(function (result) { console.log(result);});请注意,我所指的access_token对象与我先前为授权创建的对象相同。上面的代码返回401未经授权的代码。然后我尝试了以下方法:var params = { grant_type: 'refresh_token', client_id: 876787, client_secret: 'some_secret', redirect_uri: 'http://localhost:7699/profile', code: my_access_code};$http.post('https://app.asana.com/-/oauth_token', params).then(function (result) { console.log(result);});这也给我一个401未经授权的代码。我在这里做错了什么? (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 我建议您首先将一个示例从the node-asana examples directory复制粘贴到您的应用中,然后看看是否可行。如果要继续使用弹出流,我怀疑您缺少的是在popup_receiver.html中对Asana.auth.PopupFlow.runReceiver();的调用。该页面应该在您的redirect_uri指向的页面上,并告诉创建弹出窗口的页面需要进行后续请求的身份验证数据。还要注意发起身份验证请求(popup.html)的页面如何包含在传递给then的回调中进行身份验证之后发生的操作:这确保了这些操作仅在用户通过弹出窗口完成身份验证之后才发生。 (adsbygoogle = window.adsbygoogle || []).push({});
10-07 14:42