Asana NodeJS API - 使用 client.useOauth 时无法验证请求错误
Asana NodeJS API - Cannot authenticate request error when using client.useOauth
我目前正在设置并与 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)
如能提供有关可能导致此问题的帮助,我们将不胜感激!
已修复:我的问题是我传递两个标记的方式,client.useOauth 需要看起来像这样:
client.useOauth({
credentials: { access_token, refresh_token }
});
我目前正在设置并与 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)
如能提供有关可能导致此问题的帮助,我们将不胜感激!
已修复:我的问题是我传递两个标记的方式,client.useOauth 需要看起来像这样:
client.useOauth({
credentials: { access_token, refresh_token }
});