3

I am trying to create an application where i want to fetch Outlook mails. I am using using simple OAuth 2.0 for the access token. I am successfully getting the code. When I am trying to get the access token in exchange of code I am getting 400 bad request error.

const tokenConfig = {
  code: auth_code,
  redirect_uri: redirectUri,
  scope: scopes.join(' ')
};
try {
  const result = await oauth2.authorizationCode.getToken(tokenConfig);
  const accessToken = oauth2.accessToken.create(result);
} catch (error) {
   console.log('Access Token Error', error.message);
}

Can you help what wrong I am doing. Please comment for more information.

ROOT
  • 11,363
  • 5
  • 30
  • 45
Swastik
  • 499
  • 1
  • 4
  • 10

1 Answers1

1

For me the solution was to set ModuleOptions.options.authorizationMethod to 'body':

const oAuthConfig = {
    client: {
        id: 'xxxxxxxxxx',
        secret: 'xxxxxxxxxxxxxxxx'
    },
    auth: {
        tokenHost: 'https://oauthhost.example.com/common/',
        tokenPath: 'authtokenserver/token',
        authorizePath: 'authtokenserver/authorize'
    },
    options: {
        authorizationMethod: 'body'
    }
}

Edit [6/12/2023]: Here's a link to the API documentation for simple-oauth2. I've also copied the bits that pertain to this answer below:

  • options additional options to setup how the module perform requests
    • authorizationMethod - Method used to send the client.id/client.secret authorization params at the token request. Valid options are header or body. If set to body, the bodyFormat option will be used to format the credentials. Defaults to header
jmjohnson85
  • 347
  • 4
  • 9