Change OAuth2 token URL
Use a custom decorator to change the OAuth credentials flow token URL.
Estimated time: 20 minutes
Step-by-step instructions
-
Add environment variables to the API version's settings.
-
Add this code to your repo with the API (the Redocly configuration file 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/cli').CustomRulesConfig} */ const decorators = { oas3: { 'change-token-url': ChangeTokenUrl, }, }; module.exports = { id, decorators, };
module.exports = ChangeTokenUrl; /** @type {import('@redocly/cli').OasDecorator} */ function ChangeTokenUrl() { return { SecuritySchemeFlows: { leave(flows, ctx) { if ('TOKEN_URL' in process.env && flows?.clientCredentials) { flows.clientCredentials.tokenUrl = process.env.TOKEN_URL; } } } } };