---
schema_version: "1"
id: 49d1c4c1d5454a650a7aa377bfb2d8f26d06b98041784c3344c2730a9e17f74d
title: OAuth2 Provider Module 1.1 Reference
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/oauth2-provider-module/1.1/oauth2-provider-module-reference.md
canonical_url: https://docs.mulesoft.com/oauth2-provider-module/1.1/oauth2-provider-module-reference
source_site: docs.mulesoft.com
content_type: documentation
content_hash: b21ad84b63ab0d45690f2d9748220deac9b3e50634ee7916ce344e194cff6186
description: MuleSoft Documentation Site
release: "1.1"
latest: false
---
---
product: OAuth2 Provider Module
version: 1.1
---

# OAuth2 Provider Module 1.1 Reference

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

The OAuth2 Provider module allows a Mule runtime engine (Mule) app to be configured as an
Authentication Manager in an OAuth2 dance. With this role, the application will be able to
authenticate previously registered clients, grant tokens, validate tokens, or register and delete
clients, all during the execution of a flow.

## Configurations

---

### Default Configuration

OAuth2 Provider module configuration

#### Parameters

<table><colgroup><col> <col> <col> <col> <col></colgroup><thead><tr><th>Name</th><th>Type</th><th>Description</th><th>Default Value</th><th>Required</th></tr></thead><tbody><tr><td><p><strong>Name</strong></p></td><td><div><div><p>String</p></div></div></td><td><div><div><p>The name for this configuration. Connectors reference the configuration with this name.</p></div></div></td><td><div></div></td><td><div><div><p>x</p></div></div></td></tr><tr><td><p><strong>Provider Name</strong></p></td><td><div><div><p>String</p></div></div></td><td><div><div><p>The provider name supplied to customers of the API. This is used for some responses of the OAuth2 API.</p></div></div></td><td><div></div></td><td><div></div></td></tr><tr><td><p><strong>Listener Config</strong></p></td><td><div><div><p>String</p></div></div></td><td><div><div><p>The name of an HTTP Listener Config to reference, which handles the token and authorization endpoints.</p></div></div></td><td><div></div></td><td><div><div><p>x</p></div></div></td></tr><tr><td><p><strong>Client Validation Rate Limiter</strong></p></td><td><div><div><p><a href="#PeriodRateLimiter">Period Rate Limiter</a></p></div></div></td><td><div><div><p>The rate limiter used to control access to certain operations. If none is specified, PeriodRateLimiter is used as the default.</p></div></div></td><td><div></div></td><td><div></div></td></tr><tr><td><p><strong>Client Store</strong></p></td><td><div><div><p>Object Store</p></div></div></td><td><div><div><p>A store that allows retrieving client configuration information, like their secret. If no client store is provided, a default in memory object store is configured.</p></div></div></td><td><div></div></td><td><div></div></td></tr><tr><td><p><strong>Resource Owner Security Provider</strong></p></td><td><div><div><p>String</p></div></div></td><td><div><div><p>The security provider used to authenticate resource owners. Not needed if only the CLIENT_CREDENTIALS grant type is used. Refer to an example with Spring module in <a href="https://docs.mulesoft.com/mule-runtime/latest/securing">migrating the OAuth2 provider</a> documentation.</p></div></div></td><td><div></div></td><td><div></div></td></tr><tr><td><p><strong>Client Security Provider</strong></p></td><td><div><div><p>String</p></div></div></td><td><div><div><p>The security provider used to authenticate clients. Not needed if only public clients or private clients with secrets are used</p></div></div></td><td><div></div></td><td><div></div></td></tr><tr><td><p><strong>Token Generator Strategy</strong></p></td><td><div><div><p>TokenGeneratorStrategy</p></div></div></td><td><div><div><p>The strategy used to generate access tokens. Should reference a class that implements TokenGeneratorStrategy.</p></div></div></td><td><div></div></td><td><div></div></td></tr><tr><td><p><strong>Supported Grant Types</strong></p></td><td><div><div><p>Enumeration, list of:</p></div><div><ul><li><p>AUTHORIZATION_CODE</p></li><li><p>IMPLICIT</p></li><li><p>RESOURCE_OWNER_PASSWORD_CREDENTIALS</p></li><li><p>CLIENT_CREDENTIALS</p></li></ul></div></div></td><td><div><div><p>The comma-separated grant types this provider supports. If none specified, only the authorization code grant type is supported.</p></div></div></td><td><div><div><p>AUTHORIZATION_CODE</p></div></div></td><td><div></div></td></tr><tr><td><p><strong>Scopes</strong></p></td><td><div><div><p>String</p></div></div></td><td><div><div><p>A comma-separated list of supported scopes.</p></div></div></td><td><div></div></td><td><div></div></td></tr><tr><td><p><strong>Default Scopes</strong></p></td><td><div><div><p>String</p></div></div></td><td><div><div><p>A comma-separated list of the default scopes a client should have if none is defined.</p></div></div></td><td><div></div></td><td><div></div></td></tr><tr><td><p><strong>Token Config</strong></p></td><td><div><div><p><a href="#TokenConfig">Token Configuration</a></p></div></div></td><td><div><div><p>Information for configuring token related behavior.</p></div></div></td><td><div></div></td><td><div></div></td></tr><tr><td><p><strong>Authorization Config</strong></p></td><td><div><div><p><a href="#AuthorizationConfig">Authorization Config</a></p></div></div></td><td><div><div><p>Information for configuring authorization handling behavior</p></div></div></td><td><div></div></td><td><div></div></td></tr><tr><td><p><strong>Clients</strong></p></td><td><div><div><p>Array of <a href="#Client">Client</a></p></div></div></td><td><div><div><p>A list of clients.</p></div></div></td><td><div></div></td><td><div></div></td></tr><tr><td><p><strong>Expiration Policy</strong></p></td><td><div><div><p><a href="#ExpirationPolicy">Expiration Policy</a></p></div></div></td><td><div><div><p>Configures the minimum amount of time that a dynamic configuration instance can remain idle before Mule considers it eligible for expiration. This does not mean that the platform expires the instance at the exact moment that it becomes eligible. Mule purges the instances as appropriate.</p></div></div></td><td><div></div></td><td><div></div></td></tr></tbody></table>

## Operations

- [Create Client](#createClient)

- [Delete Client](#deleteClient)

- [Revoke Token](#revokeToken)

- [Validate Token](#validateToken)

### Create Client

`<oauth2-provider:create-client>`

Creates a new client and saves it in the configured client store.

```xml
<oauth2-provider:create-client
	doc:name="Create client"
	config-ref="OAuth2_Provider_Config"
	clientId="#[payload.clientId]"
	secret="#[payload.clientSecret]"
	clientName="#[payload.clientName]"
	description="#[payload.clientDescription]"
	principal="#[payload.clientPrincipal]"
	redirectUris="#[payload.redirectUris]"
	authorizedGrantTypes="#[payload.authorizedGrantTypes]"
	scopes="#[payload.scopes]"
	type="PUBLIC"
	failIfPresent="false"/>
```

#### Parameters

<table><colgroup><col> <col> <col> <col> <col></colgroup><thead><tr><th>Name</th><th>Type</th><th>Description</th><th>Default Value</th><th>Required</th></tr></thead><tbody><tr><td><p><strong>Configuration</strong></p></td><td><div><div><p>String</p></div></div></td><td><div><div><p>The name of a globally defined OAuth Provider configuration to use for token validation.</p></div></div></td><td><div></div></td><td><div><div><p>x</p></div></div></td></tr><tr><td><p><strong>Client Id</strong></p></td><td><div><div><p>String</p></div></div></td><td><div><div><p>The ID to assign to the created client.</p></div></div></td><td><div></div></td><td><div><div><p>x</p></div></div></td></tr><tr><td><p><strong>Type</strong></p></td><td><div><div><p>Enumeration, one of:</p></div><div><ul><li><p>CONFIDENTIAL</p></li><li><p>PUBLIC</p></li></ul></div></div></td><td><div><div><p>The type of the client. Allowed values are PUBLIC: Clients incapable of maintaining the confidentiality of their credentials, or CONFIDENTIAL: Clients capable of maintaining the confidentiality of their credentials.</p></div></div></td><td><div><div><p>PUBLIC</p></div></div></td><td><div></div></td></tr><tr><td><p><strong>Secret</strong></p></td><td><div><div><p>String</p></div></div></td><td><div></div></td><td><div></div></td><td><div></div></td></tr><tr><td><p><strong>Client Name</strong></p></td><td><div><div><p>String</p></div></div></td><td><div><div><p>A friendly name for the client.</p></div></div></td><td><div></div></td><td><div></div></td></tr><tr><td><p><strong>Description</strong></p></td><td><div><div><p>String</p></div></div></td><td><div><div><p>A brief description of the client.</p></div></div></td><td><div></div></td><td><div></div></td></tr><tr><td><p><strong>Principal</strong></p></td><td><div><div><p>String</p></div></div></td><td><div><div><p>An optional principal to use when the ID can’t be used with the security provider.</p></div></div></td><td><div></div></td><td><div></div></td></tr><tr><td><p><strong>Redirect Uris</strong></p></td><td><div><div><p>Array of String</p></div></div></td><td><div><div><p>An expression that resolves to a list of redirect URIs used for when the client makes requests to the OAuth Provider.</p></div></div></td><td><div></div></td><td><div></div></td></tr><tr><td><p><strong>Authorized Grant Types</strong></p></td><td><div><div><p>Array of Enumeration, one of:</p></div><div><ul><li><p>AUTHORIZATION_CODE</p></li><li><p>REFRESH_TOKEN</p></li><li><p>TOKEN</p></li><li><p>PASSWORD</p></li><li><p>CLIENT_CREDENTIALS</p></li></ul></div></div></td><td><div><div><p>An expression that resolves to a list of the authorized grant types that the client can use to request a token.</p></div></div></td><td><div></div></td><td><div></div></td></tr><tr><td><p><strong>Scopes</strong></p></td><td><div><div><p>Array of String</p></div></div></td><td><div><div><p>An expression that resolves to a list of supported scopes by the client. If none are provided, the default scopes of the <a href="#general-configuration">General Configuration</a> are used.</p></div></div></td><td><div></div></td><td><div></div></td></tr><tr><td><p><strong>Fail If Present</strong></p></td><td><div><div><p>Boolean</p></div></div></td><td><div><div><p>Defines what to do if a client with the same ID is already registered. If <code>true</code>, an error is raised. Otherwise, the client is updated.</p></div></div></td><td><div><div><p><code>false</code></p></div></div></td><td><div></div></td></tr></tbody></table>

### For Configurations

[Default Configuration](#config)

#### Throws

- OAUTH2-PROVIDER:CLIENT\_ALREADY\_EXISTS - If a client already exists with the same client ID, and
  **Fail If Present** is set to `true`.

- OAUTH2-PROVIDER:INVALID\_CONFIGURATION - If the provided parameters are not valid, such as having
  **Authorized Grant Types** of AUTHORIZATION\_CODE but without a redirect URI.

### Delete Client

`<oauth2-provider:delete-client>`

Deletes a client from the store.

#### Parameters

<table><colgroup><col> <col> <col> <col> <col></colgroup><thead><tr><th>Name</th><th>Type</th><th>Description</th><th>Default Value</th><th>Required</th></tr></thead><tbody><tr><td><p><strong>Configuration</strong></p></td><td><div><div><p>String</p></div></div></td><td><div><div><p>The name of a globally defined OAuth Provider configuration to use for token validation.</p></div></div></td><td><div></div></td><td><div><div><p>x</p></div></div></td></tr><tr><td><p><strong>Client Id</strong></p></td><td><div><div><p>String</p></div></div></td><td><div><div><p>The ID of the client to be deleted.</p></div></div></td><td><div></div></td><td><div><div><p>x</p></div></div></td></tr></tbody></table>

### For Configurations

[Default Configuration](#config)

#### Throws

OAUTH2-PROVIDER:NO\_SUCH\_CLIENT - The client to be deleted does not exist.

### Revoke Token

`<oauth2-provider:revoke-token>`

Revokes an access token or refresh token, invalidating the related refresh token or access token as
well. If client credentials need to be validated, use the validateClient credential before revoking
the token.

#### Parameters

<table><colgroup><col> <col> <col> <col> <col></colgroup><thead><tr><th>Name</th><th>Type</th><th>Description</th><th>Default Value</th><th>Required</th></tr></thead><tbody><tr><td><p><strong>Configuration</strong></p></td><td><div><div><p>String</p></div></div></td><td><div><div><p>The name of a globally defined OAuth Provider configuration to use for token validation.</p></div></div></td><td><div></div></td><td><div><div><p>x</p></div></div></td></tr><tr><td><p><strong>Token</strong></p></td><td><div><div><p>String</p></div></div></td><td><div><div><p>The token to revoke, it can be an access token or a refresh token.</p></div></div></td><td><div></div></td><td><div><div><p>x</p></div></div></td></tr></tbody></table>

### For Configurations

[Default Configuration](#config)

#### Throws

OAUTH2-PROVIDER:INVALID\_TOKEN - The token to be revoked is not valid.

### Validate Token

`<oauth2-provider:validate-token>`

Checks that a valid access token is provided. Validates that the given token was granted and is in a
valid state. Also, if defined, checks that the token scopes or resource owner roles match the
provided ones.

If the provided token is valid, the operation sets the payload as a JSON with the following
information:

- expires\_in:

  Time remaining for the token to be considered invalid, in seconds.

- scope:

  Space separated scopes associated with the token.

- client\_id:

  ID of the client that requested this token.

- username:

  Username of the resource owner that authorized this token to be requested.

To preserve the payload set before executing the operation, you can use the `target` and
`targetValue` attributes to set the JSON information in a variable instead of overwriting the
payload.

Validate Token parameters:

#### Parameters

<table><colgroup><col> <col> <col> <col> <col></colgroup><thead><tr><th>Name</th><th>Type</th><th>Description</th><th>Default Value</th><th>Required</th></tr></thead><tbody><tr><td><p><strong>Configuration</strong></p></td><td><div><div><p>String</p></div></div></td><td><div><div><p>The name of the configuration to use.</p></div></div></td><td><div></div></td><td><div><div><p>x</p></div></div></td></tr><tr><td><p><strong>Access Token</strong></p></td><td><div><div><p>String</p></div></div></td><td><div></div></td><td><div><div><p>#[(attributes.headers['authorization'] splitBy ' ')[1]]</p></div></div></td><td><div></div></td></tr><tr><td><p><strong>Scopes</strong></p></td><td><div><div><p>Array of String</p></div></div></td><td><div><div><p>An expression that resolves to a list of scopes to enforce when validating the token.</p></div></div></td><td><div></div></td><td><div></div></td></tr><tr><td><p><strong>Resource Owner Roles</strong></p></td><td><div><div><p>Array of String</p></div></div></td><td><div><div><p>The resource owner roles to enforce when validating the token. This is an expression that resolves to a list of resource owner roles to enforce when validating the token.</p></div></div></td><td><div></div></td><td><div></div></td></tr><tr><td><p><strong>Target Variable</strong></p></td><td><div><div><p>String</p></div></div></td><td><div><div><p>The name of a variable to store the operation’s output.</p></div></div></td><td><div></div></td><td><div></div></td></tr><tr><td><p><strong>Target Value</strong></p></td><td><div><div><p>String</p></div></div></td><td><div><div><p>An expression to evaluate against the operation’s output and store the expression outcome in the target variable</p></div></div></td><td><div><div><p>#[payload]</p></div></div></td><td><div></div></td></tr></tbody></table>

#### Output

<table><colgroup><col> <col></colgroup><tbody><tr><td><p>Type</p></td><td><p>String</p></td></tr></tbody></table>

### For Configurations

[Default Configuration](#config)

#### Throws

OAUTH2-PROVIDER:TOKEN\_UNAUTHORIZED - The token being validated is not valid.

## Types

### Token Configuration

Configuration related to token handling and the token endpoint.

<table><colgroup><col> <col> <col> <col> <col></colgroup><thead><tr><th>Field</th><th>Type</th><th>Description</th><th>Default Value</th><th>Required</th></tr></thead><tbody><tr><td><p><strong>Path</strong></p></td><td><div><div><p>String</p></div></div></td><td><div><div><p>Endpoint to call when wanting to request a new token</p></div></div></td><td><div><div><p>/token</p></div></div></td><td><div></div></td></tr><tr><td><p><strong>Token Store</strong></p></td><td><div><div><p>Object Store</p></div></div></td><td><div><div><p>ObjectStore configuration information for storing token related data</p></div></div></td><td><div></div></td><td><div></div></td></tr><tr><td><p><strong>Refresh Token Strategy</strong></p></td><td><div><div><p>One of:</p></div><div><ul><li><p><a href="#noRefreshToken">No Refresh Token</a></p></li><li><p><a href="#singleRefreshToken">Single Refresh Token</a></p></li><li><p><a href="#multipleRefreshTokens">Multiple Refresh Tokens</a></p></li></ul></div></div></td><td><div><div><p>The refresh token strategy to use. By default no refresh token should be generated</p></div></div></td><td><div></div></td><td><div></div></td></tr><tr><td><p><strong>Token Ttl</strong></p></td><td><div><div><p>Number</p></div></div></td><td><div><div><p>The time in seconds before an access token code expires.</p></div></div></td><td><div><div><p>86400</p></div></div></td><td><div></div></td></tr><tr><td><p><strong>Token Ttl Time Unit</strong></p></td><td><div><div><p>Enumeration, one of:</p></div><div><ul><li><p>NANOSECONDS</p></li><li><p>MICROSECONDS</p></li><li><p>MILLISECONDS</p></li><li><p>SECONDS</p></li><li><p>MINUTES</p></li><li><p>HOURS</p></li><li><p>DAYS</p></li></ul></div></div></td><td><div><div><p>The time unit for the token ttl.</p></div></div></td><td><div><div><p>SECONDS</p></div></div></td><td><div></div></td></tr></tbody></table>

### Authorization Config

Configuration related to authorization code handling and the authorization endpoint.

<table><colgroup><col> <col> <col> <col> <col></colgroup><thead><tr><th>Field</th><th>Type</th><th>Description</th><th>Default Value</th><th>Required</th></tr></thead><tbody><tr><td><p><strong>Login Page</strong></p></td><td><div><div><p>String</p></div></div></td><td><div><div><p>Relative file path to the web page for the resource owner to provide its credentials.<br>Keep in mind that if the default page is not used, you need to handle any external files referenced in the configured HTML. They are not handled by the OAuth provider.<br>For example, if the login page HTML references an external <code>.css</code> style file, an endpoint that provides that file must exist. See <a href="https://docs.mulesoft.com/http-connector/latest/http-documentation#loadStaticResource">HTTP Load Static Resource</a>.</p></div></div></td><td><div><div><p>www-static/auth.html</p></div></div></td><td><div></div></td></tr><tr><td><p><strong>Path</strong></p></td><td><div><div><p>String</p></div></div></td><td><div><div><p>The URL relative path to the authorization endpoint in the HTTP server for listening to authorization requests.</p></div></div></td><td><div><div><p>/authorize</p></div></div></td><td><div></div></td></tr><tr><td><p><strong>Authorization Code Store</strong></p></td><td><div><div><p>Object Store</p></div></div></td><td><div><div><p>A reference to a globally defined object store or a definition of a private object store. It’s used to store generated authorization codes.</p></div></div></td><td><div><div><p>A persistent object store created from the ObjectStoreManager with an entry TTL of 600 SECONDS.</p></div></div></td><td><div></div></td></tr></tbody></table>

### Client

All registered clients are authorized to request tokens. The list can be modified in runtime by the
[Create Client](#createClient) and [Delete Client](#deleteClient) operations.

```xml
<oauth2-provider:clients>
    <oauth2-provider:client
		clientId="clientId1"
		clientName="someClient"
		secret="clientSecret1"
		principal="clusr"
		description="Some test client"
		type="CONFIDENTIAL">
        <oauth2-provider:client-redirect-uris>
            <oauth2-provider:client-redirect-uri
            	value="http://fake/redirect"/>
        </oauth2-provider:client-redirect-uris>
        <oauth2-provider:client-authorized-grant-types>
            <oauth2-provider:client-authorized-grant-type
            	value="AUTHORIZATION_CODE"/>
        </oauth2-provider:client-authorized-grant-types>
        <oauth2-provider:client-scopes>
            <oauth2-provider:client-scope value="USER"/>
        </oauth2-provider:client-scopes>
    </oauth2-provider:client>
</oauth2-provider:clients>
```

Each registered client has an entry with the following information:

<table><colgroup><col> <col> <col> <col> <col></colgroup><thead><tr><th>Field</th><th>Type</th><th>Description</th><th>Default Value</th><th>Required</th></tr></thead><tbody><tr><td><p><strong>Client Id</strong></p></td><td><div><div><p>String</p></div></div></td><td><div><div><p>A unique ID that will used to reference the client</p></div></div></td><td><div></div></td><td><div><div><p>x</p></div></div></td></tr><tr><td><p><strong>Principal</strong></p></td><td><div><div><p>String</p></div></div></td><td><div><div><p>An optional principal to use when the ID can’t be used with the security provider. For some security providers, the clientId can’t be used for the client username. In those cases, the client’s principal is used for authentication.</p></div></div></td><td><div></div></td><td><div></div></td></tr><tr><td><p><strong>Client Name</strong></p></td><td><div><div><p>String</p></div></div></td><td><div><div><p>The name of the client</p></div></div></td><td><div></div></td><td><div></div></td></tr><tr><td><p><strong>Description</strong></p></td><td><div><div><p>String</p></div></div></td><td><div><div><p>A short description for the client</p></div></div></td><td><div></div></td><td><div></div></td></tr><tr><td><p><strong>Secret</strong></p></td><td><div><div><p>String</p></div></div></td><td><div><div><p>A client secret used to authenticate the client. Only required if <strong>Type</strong> is CONFIDENTIAL.</p></div></div></td><td><div></div></td><td><div></div></td></tr><tr><td><p><strong>Client Redirect Uris</strong></p></td><td><div><div><p>Array of String</p></div></div></td><td><div><div><p>List of registered redirect URIs to use to respond to the client once the request is processed.</p></div><div><p>Most requests allow the definition of new redirection URIs so these are not always taken into account. See also <a href="#newvaluehandling">New Value Handling</a>.</p></div><div><p><code>&lt;oauth2-provider:client-scope value="USER"/&gt;</code></p></div></div></td><td><div></div></td><td><div></div></td></tr><tr><td><p><strong>Client Authorized Grant Types</strong></p></td><td><div><div><p>Array of Enumeration, one of:</p></div><div><ul><li><p>AUTHORIZATION_CODE</p></li><li><p>REFRESH_TOKEN</p></li><li><p>TOKEN</p></li><li><p>PASSWORD</p></li><li><p>CLIENT_CREDENTIALS</p></li></ul></div></div></td><td><div><div><p>The grant types that define which OAuth flows this client will be able to be successfully execute to get a token. See also <a href="#newvaluehandling">New Value Handling</a>.</p></div></div></td><td><div></div></td><td><div></div></td></tr><tr><td><p><strong>Client Scopes</strong></p></td><td><div><div><p>Array of String</p></div></div></td><td><div><div><p>The scopes that will match this client. If a request is received with a matching client ID but with different scopes, it will not be processed. See also <a href="#newvaluehandling">New Value Handling</a>.</p></div></div></td><td><div></div></td><td><div></div></td></tr><tr><td><p><strong>Type</strong></p></td><td><div><div><p>Enumeration, one of:</p></div><div><ul><li><p>CONFIDENTIAL</p></li><li><p>PUBLIC</p></li></ul></div></div></td><td><div><div><p>The client type defines if the client is able to maintain confidentiality for its credentials. Allowed values are <code>PUBLIC</code>, where clients do not maintain the confidentiality of their credentials, or <code>CONFIDENTIAL</code>, where clients maintain the confidentiality of their credentials.</p></div></div></td><td><div><div><p><code>PUBLIC</code></p></div></div></td><td><div></div></td></tr></tbody></table>

For client redirect URIs, client authorized grant types, or client scopes, give each new value a new
XML tag:

`<oauth2-provider:client-redirect-uri value="http://fake/redirect"/>`

`<oauth2-provider:client-authorized-grant-type value="AUTHORIZATION_CODE"/>`

### Expiration Policy

<table><colgroup><col> <col> <col> <col> <col></colgroup><thead><tr><th>Field</th><th>Type</th><th>Description</th><th>Default Value</th><th>Required</th></tr></thead><tbody><tr><td><p><strong>Max Idle Time</strong></p></td><td><div><div><p>Number</p></div></div></td><td><div><div><p>A scalar time value for the maximum amount of time a dynamic configuration instance should be allowed to be idle before it’s considered eligible for expiration</p></div></div></td><td><div></div></td><td><div></div></td></tr><tr><td><p><strong>Time Unit</strong></p></td><td><div><div><p>Enumeration, one of:</p></div><div><ul><li><p>NANOSECONDS</p></li><li><p>MICROSECONDS</p></li><li><p>MILLISECONDS</p></li><li><p>SECONDS</p></li><li><p>MINUTES</p></li><li><p>HOURS</p></li><li><p>DAYS</p></li></ul></div></div></td><td><div><div><p>A time unit that qualifies the maxIdleTime attribute</p></div></div></td><td><div></div></td><td><div></div></td></tr></tbody></table>

### No Refresh Token

No refresh token is granted with every access token. As a consequence, when a refresh token request
comes, it is always rejected.

<table><colgroup><col> <col> <col> <col> <col></colgroup><thead><tr><th>Field</th><th>Type</th><th>Description</th><th>Default Value</th><th>Required</th></tr></thead><tbody><tr><td><p><strong>Token Generator Strategy</strong></p></td><td><div><div><p>TokenGeneratorStrategy</p></div></div></td><td><div></div></td><td><div></div></td><td><div></div></td></tr></tbody></table>

### Single Refresh Token

For every new access token that is granted, a single refresh token is associated with it. That same
refresh token can be used every time the access token is refreshed.

<table><colgroup><col> <col> <col> <col> <col></colgroup><thead><tr><th>Field</th><th>Type</th><th>Description</th><th>Default Value</th><th>Required</th></tr></thead><tbody><tr><td><p><strong>Object Store</strong></p></td><td><div><div><p>Object Store</p></div></div></td><td><div><div><p>A reference to a globally defined object store or a definition of a private object store for storing generated refresh tokens. The object store must be different from the access token object store.</p></div></div></td><td><div><div><p>A persistent object store created from the ObjectStoreManager with an entry TTL of 86400 seconds.</p></div></div></td><td><div></div></td></tr></tbody></table>

### Multiple Refresh Tokens

A new refresh token is generated every time a refresh token request is executed. After that, the
previous refresh token is invalidated.

<table><colgroup><col> <col> <col> <col> <col></colgroup><thead><tr><th>Field</th><th>Type</th><th>Description</th><th>Default Value</th><th>Required</th></tr></thead><tbody><tr><td><p><strong>Object Store</strong></p></td><td><div><div><p>Object Store</p></div></div></td><td><div><div><p>A reference to a globally defined object store, or a definition of a private object store that stores the generated refresh tokens. The object store must be different from the access token object store.</p></div></div></td><td><div><div><p>A persistent object store created from the ObjectStoreManager with an entry TTL of 86400 seconds.</p></div></div></td><td><div></div></td></tr></tbody></table>

### Period Rate Limiter

Period Rate Limiter handles rate limiting based on a time period.

You can configure a mechanism to prevent the continuous client validation when it’s using invalid
credentials.

<table><colgroup><col> <col> <col> <col> <col></colgroup><thead><tr><th>Field</th><th>Type</th><th>Description</th><th>Default Value</th><th>Required</th></tr></thead><tbody><tr><td><p><strong>Duration</strong></p></td><td><div><div><p>Number</p></div></div></td><td><div><div><p>The time to wait before resetting the rate limiter. That means that during time intervals of <em>duration</em> length, every time a client validation fails, it will be added to the failure count.</p></div></div></td><td><div><div><p>600</p></div></div></td><td><div></div></td></tr><tr><td><p><strong>Duration Time Unit</strong></p></td><td><div><div><p>Enumeration, one of:</p></div><div><ul><li><p>NANOSECONDS</p></li><li><p>MICROSECONDS</p></li><li><p>MILLISECONDS</p></li><li><p>SECONDS</p></li><li><p>MINUTES</p></li><li><p>HOURS</p></li><li><p>DAYS</p></li></ul></div></div></td><td><div></div></td><td><div><div><p>SECONDS</p></div></div></td><td><div></div></td></tr><tr><td><p><strong>Maximum Failure Count</strong></p></td><td><div><div><p>Number</p></div></div></td><td><div><div><p>Maximum number of failures allowed within the period before preemptively rejecting requests.</p></div></div></td><td><div><div><p>5</p></div></div></td><td><div></div></td></tr></tbody></table>

## OAuth Dance

Because the OAuth dance is done through HTTP, the OAuth2 Provider makes use of the
[Mule HTTP Connector](https://docs.mulesoft.com/http-connector/latest/).

As a consequence, apart from the definition of an OAuth2 provider configuration, the Mule
application must also have an HTTP Listener configuration to be used by the provider.

Once configured, the provider works as follows:

Two HTTP endpoints are created for listening to Authentication Code and Token request as stated by
the OAuth2 definition. Those work independently from the Mule application and respond via HTTP.

The provider defines an operation: [Validate Token](#validateToken) that can check if a token is
authorized. That operation can be added anywhere in a flow to control its execution. If the token is
indeed authorized, the flow continues executing, setting token information in the payload;
otherwise, a `TOKEN_UNAUTHORIZED` error is raised. You need to add the operation to the parts of the
application that require token authorization.

Since token validation is almost always used together with an HTTP Listener, in case it fails, the
Listener’s response mechanism can handle the error and properly respond to the requester. Additional
logic can be added for handling that type of error.

Lastly, additional operations are provided to add or delete clients and to revoke tokens if needed.

## Security Providers

As seen in the [General Configuration](#general-configuration), two security providers should be
defined in the app to be later referenced by the OAuth2 Configuration element.

One way of doing this is using the Spring Framework, defining both security providers, and then
using the [Spring Module](https://docs.mulesoft.com/spring-module/latest/) to add the providers to the Mule Security
Manager:

```xml
<spring:security-manager>
    <spring:delegate-security-provider
    	name="clientSecurityProvider"
        delegate-ref="clientAuthenticationManager"/>
    <spring:delegate-security-provider
    	name="resourceOwnerSecurityProvider"
		delegate-ref="resourceOwnerAuthenticationManager"/>
</spring:security-manager>
```

## General Configuration

```xml
<oauth2-provider:config
	name="OAuth2Provider"
	listenerConfig="httpListenerConfig"
	resourceOwnerSecurityProvider="resourceOwnerSecurityProvider"
	clientSecurityProvider="clientSecurityProvider"
	supportedGrantTypes="AUTHORIZATION_CODE"
	scopes="USER,ADMIN"
	defaultScopes="USER"
	clientStore="clientObjectStore">

     <oauth2-provider:client-validation-rate-limiter>
        <oauth2-provider:period-rate-limiter
        	duration="600"
             durationTimeUnit="SECONDS"
             maximumFailureCount="5"/>
     </oauth2-provider:client-validation-rate-limiter>

     <oauth2-provider:token-config
     	path="/token"
		tokenStore="tokenObjectStore"
		tokenTtl="86400"
		tokenTtlTimeUnit="SECONDS">

        <oauth2-provider:refresh-token-strategy>
            <oauth2-single-refresh-token
            	objectStore="refreshTokenObjectStore"/>
        </oauth2-provider:refresh-token-strategy>

     </oauth2-provider:token-config>
     <oauth2-provider:authorization-config
     	loginPage="static/auth.html"
		path="/authorize"
		objectStore="authorizationCodeObjectStore"/>

     <oauth2-provider:clients>
         <oauth2-provider:client
         	clientId="clientId1"
			clientName="someClient"
			secret="clientSecret1"
			principal="clusr"
			description="Some test client"
			type="CONFIDENTIAL">

             <oauth2-provider:client-redirect-uris>
                 <oauth2-provider:client-redirect-uri
                 	value="http://fake/redirect"/>
             </oauth2-provider:client-redirect-uris>

             <oauth2-provider:client-authorized-grant-types>
                 <oauth2-provider:client-authorized-grant-type
                 	value="AUTHORIZATION_CODE"/>
             </oauth2-provider:client-authorized-grant-types>

             <oauth2-provider:client-scopes>
                 <oauth2-provider:client-scope value="USER"/>
             </oauth2-provider:client-scopes>

         </oauth2-provider:client>
     </oauth2-provider:clients>
 </oauth2-provider:config>
```

## See Also

[Salesforce Help](https://help.salesforce.com)
