Skip to content

Oauth2 replies 400 with no useful error message #287

Description

@juliofarah

Hi! I've been working on an integration with Asana and realized that there is no internal helper function for Oauth2-based authentication like there was on the first major version of the node client.

When I try to use the Oauth2 endpoints documented here https://developers.asana.com/docs/oauth#pkce-oauth-extension I always get a 400 with no useful error message.

Here's my auth code:

    const redirectUri = `${process.env.NEXT_PUBLIC_OAUTH_REDIRECT_URI}/asana`;

    const body = {
      grant_type: 'authorization_code',
      client_id: process.env.ASANA_CLIENT_ID,
      client_secret: process.env.ASANA_CLIENT_SECRET,
      redirect_uri: redirectUri,
      code: req.query.code,
    };

    const config = {
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
    };

    const tokenResponse = await axios.post(`https://app.asana.com/-/oauth_token`, body, config);

This is what the response looks like:

{
   "message":"Request failed with status code 400",
   "name":"AxiosError",
   "config":{
      "transitional":{
         "silentJSONParsing":true,
         "forcedJSONParsing":true,
         "clarifyTimeoutError":false
      },
      "transformRequest":[
         null
      ],
      "transformResponse":[
         null
      ],
      "timeout":0,
      "xsrfCookieName":"XSRF-TOKEN",
      "xsrfHeaderName":"X-XSRF-TOKEN",
      "maxContentLength":-1,
      "maxBodyLength":-1,
      "env":{
         
      },
      "headers":{
         "Accept":"application/json, text/plain, */*",
         "Content-Type":"application/x-www-form-urlencoded",
         "User-Agent":"axios/0.27.2",
         "Content-Length":244
      },
      "method":"post",
      "url":"https://app.asana.com/-/oauth_token",
      "data":"{\"grant_type\":\"authorization_code\",\"client_id\":\"<REDACTED>\",\"client_secret\":\"<REDACTED>\",\"redirect_uri\":\"<REDCATED>/oauth/asana\",\"code\":\"<REDACTED>\"}"
   },
   "code":"ERR_BAD_REQUEST",
   "status":400
}

Am I missing something obvious here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions