Change OAuth2 token URL

Use a custom decorator to change the OAuth credentials flow token URL.

Estimated time: 20 minutes

Step-by-step instructions

  1. Add environment variables to the API version's settings. environment variables
  2. Add this code to your repo with the API (the .redocly.yaml confirm is an example).

    .redocly.yamlacme-plugin.jsdecorators/change-token-url.js
    plugins:
      lint:
    extends:
      - recommended
    plugins:
      - './plugins/acme-plugin.js'
    decorators:
      acme/change-token-urls: error
    const ChangeTokenUrl = require('./decorators/change-token-url');
    const id = 'acme';
    
    /** @type {import('@redocly/openapi-cli').CustomRulesConfig} */
    const decorators = {
      oas3: {
        'change-token-url': ChangeTokenUrl,
      },
    };
    
    module.exports = {
      id,
      decorators,
    };
    module.exports = ChangeTokenUrl;
    
    /** @type {import('@redocly/openapi-cli').OasDecorator} */
    function ChangeTokenUrl() {
      return {
        SecuritySchemeFlows: {
          leave(flows, ctx) {
            if ('TOKEN_URL' in process.env && flows?.clientCredentials) {
              flows.clientCredentials.tokenUrl = process.env.TOKEN_URL;
            }
          }
        }
      }
    };