OAuth2 token customization
The Infinity data source supports OAuth2 authentication with advanced customization options for token headers and token templates. This feature allows you to customize how OAuth2 access tokens are sent in HTTP requests, accommodating APIs that don’t follow standard OAuth2 patterns.
When to use custom token configuration
By default, OAuth2 authentication sends the access token in the standard format:
Authorization: Bearer <access_token>Use custom token configuration when your API requires:
- A different header name (for example,
X-API-KeyorX-Access-Token) - A custom token format with different prefixes
- Access to the refresh token or token type in the header
AuthHeader option
The authHeader field specifies a custom header name for the OAuth2 token.
Example values:
X-API-KeyX-Access-TokenBearer-Token
TokenTemplate option
The tokenTemplate field specifies a custom format for the token value using placeholders.
Available placeholders:
Example templates:
Configuration example
To configure custom OAuth2 token handling, add the following to your data source provisioning YAML:
apiVersion: 1
datasources:
- name: Custom API
type: yesoreyeram-infinity-datasource
jsonData:
oauthPassThru: false
oauth2:
oauth2_type: client_credentials
client_id: your-client-id
token_url: https://auth.example.com/oauth/token
authHeader: X-API-Key
tokenTemplate: "ApiKey ${__oauth2.access_token}"
secureJsonData:
oauth2ClientSecret: your-client-secretThis configuration sends requests with:
X-API-Key: ApiKey abc123Instead of the default:
Authorization: Bearer abc123Configure in the UI
- In the data source configuration, expand Authentication.
- Select OAuth2 as the authentication method.
- Select your OAuth2 type (for example, Client Credentials).
- Fill in the required OAuth2 fields (Client ID, Client Secret, Token URL).
- Expand Customize OAuth2 token (Advanced).
- In the Custom Token Header field, enter your custom header name.
- In the Custom Token Template field, enter your custom token format using placeholders.
- Click Save & test.



