---
schema_version: "1"
id: a3f2a4e15e15f1e29ac9959faea5fb1d2a3a2f377f1f680e8894d3352dec0243
title: OAuth2 Provider Module Example
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/oauth2-provider-module/1.0/oauth2-provider-module-example.md
canonical_url: https://docs.mulesoft.com/oauth2-provider-module/1.0/oauth2-provider-module-example
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 4a034768d847fd4bf054e7db6667036f45e30b41c931559a58b521d300356f05
description: MuleSoft Documentation Site
release: "1.0"
latest: false
---
---
product: OAuth2 Provider Module
version: 1.0
---

# OAuth2 Provider Module Example

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

The OAuth2 Provider module supports a Mule runtime engine (Mule) application to be configured as an
Authentication Manager in an OAuth2 authorization framework. By using this module, the application
can register clients, authenticate registered clients, grant tokens, validate tokens, and delete
clients. The following example shows how to configure the **Create client** and **Validate token**
operations, that create and validate client credentials.

![OAuth provider studio flow](/mulesoft/current/en-us/oauth2-provider-module/1.0/_images/oauth2-provider-example.png)

1.  In Studio, drag the HTTP **Listener** operation to the Studio canvas.

2.  Set **Path** to `/createClient`.

3.  Set the **Connector configuration** to your desired HTTP configuration.

4.  Drag the **Create client** operation alongside the HTTP **Listener** operation.

5.  Set **Module configuration** to your desired OAuth2 provider module configuration.

6.  Set the following parameters:

    - **Client id**: `attributes.headers.client_id`

    - **Type**: `CONFIDENTIAL`

    - **Secret**: `attributes.headers.client_secret`

    - **Client name**: `attributes.headers.client_name`

    - **Description**: `””`

    - **Principal**: `””`

    - **Redirect uris**: `”demo.com”`

    - **Authorized grant types**: `”CLIENT_CREDENTIALS”`

7.  Drag a **Set Payload** component alongside the **Create client** operation.

8.  Set **Value** to `Client Created`.

9.  Drag a new HTTP **Listener** source to a new flow.

10. Set **Path** to `/validate`.

11. Drag a **Validate token** operation alongside the **Listener** source.

12. Set **Module configuration** to your desired OAuth2 provider module configuration.

13. Set **Access token** to `(attributes.headers['authorization'] splitBy ' ')[1]`.

14. Drag a **Transform Message** component alongside the **Validate token** operation.

15. In the output display, add the following DataWeave code:

    ```dataweave
    %dw 2.0
    output application/json
    ---
    {
    	"Message": "Successfully validated"
    }
    ```

16. Save and run your Mule app.

## Test your Mule App

To test the Mule app, run the following commands:

`[http://oauthtest01.us-e2.cloudhub.io/createClient](http://oauthtest01.us-e2.cloudhub.io/createClient)`
Method: GET Param: client\_id, client\_secret, client\_name

For example, setting the GET parameters fields with the following values `client_id = 123`,
`client_secret = 1234`, `client_name = abc`

Returns the following result:

```xml
{
  "Message": "Client Created"
}
```

`[http://oauthtest01.us-e2.cloudhub.io/token](http://oauthtest01.us-e2.cloudhub.io/token)` Method:
POST Param: client\_id, client\_secret, grant\_type

For example, setting the POST parameters fields with the following values: `client_id = 123`,
`client_secret = 1234`, `grant_type = CLIENT_CREDENTIALS`

Returns the following result:

```xml
{"access_token":"s143Barj7xpQP3_AGWvHRyZxFNEcgJ55XB1I3Yquj8kgem2qxqa5TpouLG3gQCr2sj170Ci1MqLd5gzF4AUpRQ",
"token_type":"Bearer",
"expires_in":86400}
```

Another option is to run the validate command:
`[http://oauthtest01.us-e2.cloudhub.io/validate](http://oauthtest01.us-e2.cloudhub.io/validate)`
Method: GET Param: Authorization

1.  Put the `token_type` received from the response data which is "Bearer".

2.  Add a space.

3.  Add the `access_token` received from the response data.

For example, the Authorization equals to the Bearer:

```xml
Bearer s143Barj7xpQP3_AGWvHRyZxFNEcgJ55XB1I3Yquj8kgem2qxqa5TpouLG3gQCr2sj170Ci1MqLd5gzF4AUpRQ
```

Returns the following result:

```xml
{
  "Message": "Successfully validated"
}
```

If the response is not valid, the result is the following:

```xml
The token received: s143BarjxpQP3_AGWvHRyZxFNEcgJ55XB1I3Yquj8kgem2qxqa5TpouLG3gQCr2sj170Ci1MqLd5gzF4AUpRQ, is not valid.
```

## See Also

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