Skip to content

Refresh Access Token when receiving 401 error #1840

Answered by PopGoesTheWza
ruslan-ncg asked this question in Q&A
Discussion options

You must be logged in to vote

Here is an excerpt of the code I use to interact with Sugar CRM Rest API with OAuth token.

/**
 * Base Got configuration for Sugar CRM API
 */
export const baseOptions: ExtendOptions = {
  agent: {
    http: new HttpAgent({keepAlive: true}),
    https: new HttpsAgent({keepAlive: true}),
  },
  prefixUrl: getBaseUrl(),
};

let token: string | undefined;

const authURL = 'oauth2/token';
const authOptions: ExtendOptions = {
  method: 'POST',
  json: {
    grant_type: 'password',
    client_id: 'sugar',
    client_secret: '',
    platform: 'base',
    ...getCredentials(),
  },
};

/** @internal Got instance to be use for authentication */
const authenticationInstance = got.extend(baseOptions, a…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@ruslan-ncg
Comment options

@PopGoesTheWza
Comment options

@ruslan-ncg
Comment options

@PopGoesTheWza
Comment options

@ruslan-ncg
Comment options

Answer selected by ruslan-ncg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants