Files
redocly-cli/docs/guides/change-token-url.md
2022-03-23 22:07:26 +00:00

1.4 KiB

redirectFrom
redirectFrom
/docs/resources/change-token-url/

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 configuration file is an example).

    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;
            }
          }
        }
      }
    };