How do I customize OAuth2 requests

Your OAuth2 provider may support non-standard parameters when initializing flows such as the authorization code flow or the token refresh flow. For example, Youtrack uses the parameter access_type in the authorization code request to decide if it returns a refresh token alongside the regular access token.

In such cases you can do pass these extra parameters using the options argument present in all the methods of the OauthFacade class:

Passing extra parameters when requesting access

Access requests are handled via the authorization code flow. To add your parameters, add a query property:

// obtain a reference to the oauth client from the application client
const { oauth } = dpapp

// request a refresh token to be sent 
oauth.access('youtrack', { 
    query: { 'access_type' : 'offline' } 
}).then(resp => console.log(resp.refresh_token))

Passing extra parameters when refreshing access

If you want to refresh an access token, you must let Deskpro know what is the storage key which points to the refresh token you obtained from a previous step. Assuming that key is named access-tokens, your code might look like this:

// obtain a reference to the oauth client from the application client
const { oauth } = dpapp

// request a refresh token to be sent 
oauth.refresh('youtrack', { 
    query: { 'refresh_token' : 'access-tokens' } 
}).then(resp => console.log(resp.access_token))

Last updated