Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAuth2 authentication with client_credentials grant fails with HTTP 520 #110

Open
razvanz opened this issue Aug 21, 2024 · 0 comments
Open

Comments

@razvanz
Copy link

razvanz commented Aug 21, 2024

I'm trying to obtain an access token using the documented OAuth2 client_credentials grant:

import { TrustpilotApi } from "trustpilot";

;(async () => {
	const client = await new TrustpilotApi({
		key: '<api_key>',
		secret: '<api_secret>',
		grantType: 'client_credentials',
		baseUrl: 'https://api.trustpilot.com'
	}).authenticate();

	const res = await client.get('/v1/business-units/all');

	console.log(res.data);
})()

However, authentication fails with:

    status: 520,             
    statusText: 'Unknown error',                                                      
    headers: Object [AxiosHeaders] {
      'content-type': 'text/plain',     
      'content-length': '0',    
      connection: 'close',      
      date: 'Tue, 20 Aug 2024 13:02:05 GMT',
      'x-cache': 'Error from cloudfront',
      via: '1.1 9aac88bd0767f985559187c36e716276.cloudfront.net (CloudFront)',
      'x-amz-cf-pop': 'CHP50-C2',                                                     
      'x-amz-cf-id': 'iX0LXSapKKvz7glJYMw9LrevY8t4kOTugsUdn1GtQavCzpVGSeE0IQ=='
    },                                
    config: {                                                                         
      transitional: [Object],       
      adapter: [Array],
      transformRequest: [Array],
      transformResponse: [Array],                                                                                                                                            
      timeout: 0,                                                                     
      xsrfCookieName: 'XSRF-TOKEN',                                                                                                                                          
      xsrfHeaderName: 'X-XSRF-TOKEN',
      maxContentLength: -1,
      maxBodyLength: -1,
      env: [Object],
      validateStatus: [Function: validateStatus],
      headers: [Object [AxiosHeaders]],
      auth: [Object],
      baseURL: 'https://api.trustpilot.com',
      method: 'post',
      url: '/v1/oauth/oauth-business-users-for-applications/accesstoken',
      data: 'grant_type=client_credentials'
    },

If I supply invalid credentials I get a different error, HTTP 401, so it's most likely a different error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant