【问题标题】:Asana NodeJS API - Cannot authenticate request error when using client.useOauthAsana NodeJS API - 使用 client.useOauth 时无法验证请求错误
【发布时间】:2021-02-01 08:27:31
【问题描述】:

我目前正在设置和集成 Asana,并希望通过库的 oAuth 端连接我的用户。在让用户导航到 Asana、授权应用程序、然后存储访问令牌和刷新令牌以供后续使用的意义上,我已经成功地让身份验证流程正常工作。我知道访问令牌会在 1 小时后过期,因此在调用 api 时最好使用东西的“client.useOauth”端来传递访问和刷新令牌允许库根据需要刷新它无需手动操作,这很棒。但是在下面的代码实现中,我收到了一个错误:

/**
 * Create a new asana client
 */
const client = Asana.Client.create({
    clientId: asanaCredentials.id,
    clientSecret: asanaCredentials.secret,
    redirectUri: asanaCredentials.redirect
});
/*
 * Get the access token and refresh token from the parameters passed in
 */
const { access_token, refresh_token } = data;
/*
 * Pass the client access & refresh tokens
 */
client.useOauth({
    access_token, refresh_token
});
/*
 * Get the users workspaces
 */
const workspaces = client.workspaces.getWorkspaces().then((result) => { return result.data; });
/*
 * Return the results back to the app
 */
return workspaces;

运行时,我打印出以下错误:

Unhandled error Error: Cannot authenticate a request without first obtaining credentials
at
OauthAuthenticator.authenticateRequest (/workspace/node_modules/asana/lib/auth/oauth_authenticator.js:42)
at
doRequest (/workspace/node_modules/asana/lib/dispatcher.js:247)
at
(/workspace/node_modules/asana/lib/dispatcher.js:295)
at
Promise._execute (/workspace/node_modules/bluebird/js/release/debuggability.js:300)
at
Promise._resolveFromExecutor (/workspace/node_modules/bluebird/js/release/promise.js:481)
at
Promise (/workspace/node_modules/bluebird/js/release/promise.js:77)
at
Dispatcher.dispatch (/workspace/node_modules/asana/lib/dispatcher.js:244)
at
Dispatcher.get (/workspace/node_modules/asana/lib/dispatcher.js:321)
at
Function.Resource.getCollection (resource.js:36)
at
Workspaces.Resource.dispatchGetCollection (resource.js:77)
at
Workspaces.getWorkspaces (/workspace/node_modules/asana/lib/resources/gen/workspaces.js:73)
at
(/workspace/lib/src/integrations.js:132)
at
Generator.next ()
at
(/workspace/lib/src/integrations.js:8)
at
Promise ()
at
__awaiter (/workspace/lib/src/integrations.js:4)

任何可能导致此问题的帮助将不胜感激,谢谢!

【问题讨论】:

    标签: javascript node.js asana


    【解决方案1】:

    已修复:我的问题是我传入两个令牌的方式,client.useOauth 需要如下所示:

    client.useOauth({
        credentials: { access_token, refresh_token }
    });
    

    【讨论】:

      猜你喜欢
      • 2020-10-15
      • 2020-04-21
      • 1970-01-01
      • 2012-04-22
      • 1970-01-01
      • 1970-01-01
      • 2019-05-06
      • 1970-01-01
      • 2021-01-07
      相关资源
      最近更新 更多