OAuth2
The oauth2 component is used to authenticate with an OAuth 2.0 server. The component sends the user to the authorization server to authenticate and receive an access token. The access token is used to authenticate the user with the application. The component can be used to authenticate with any OAuth 2.0 server.
Token must be stored in the application state to be used in the application. The onToken event is used to store the token in the application state.
Usage
components:
- name: "oauth2"
description: "oAuth2"
props:
label:
en-US: "Authenticating with OAuth 2.0"
clientId: "client-id"
clientSecret: "client-secret"
authorizationUrl: "https://example.com/oauth2/authorize"
tokenUrl: "https://example.com/oauth2/token"
scopes:
- "read"
- "write"
additionalParams: # additional parameters to be sent to the authorization server
app_name: "myapp"
additionalHeaders: # additional headers to be sent to the authorization server
app_name: "myapp"
onToken:
setData:
token: "{{ token }}"
Redirect Url
The redirect URL of the application must be set to the URL of the application with the path /oauth2/callback. For example, if the application is running on http://tms.example.com, the redirect URL must be set to http://tms.example.com/oauth2/callback.
The non-localized callback route preserves the OAuth query string and redirects to the current preferred locale route (/{locale}/oauth2/callback) before exchanging the authorization code. This keeps OAuth providers configured with the stable /oauth2/callback URL while letting the callback page render inside the localized app shell.
Add this URL to the list of redirect URLs in the application settings of the authorization server.