Step 1: Create an Anypoint Studio application using Mule OAuth 2.0 Provider
A sample Anypoint Studio application is attached at the bottom of this article. oauth-2-provider.jar shows what you should have at the end of Step 1.
A. Configuring your application
Client Object Store:
Token Object Store:
OAuth2 Provider Config XML:
<oauth2-provider:config name=”Oauth2_Provider_Config” doc:name=”Oauth2 Provider Config” doc:id=”adcc2165-73cd-4c0e-8d79-4fedd5704714″ providerName=”Oauth2_Provider”
listenerConfig=”HTTP_Listener_config” clientStore=”client_objectStore” supportedGrantTypes=”CLIENT_CREDENTIALS”>
<oauth2-provider:token-config tokenStore=”token_objetStore” />
</oauth2-provider:config>
OAuth2 Provider Config UI:
B. Client creation flow
OAuth2 Client Creation Flow:
Create client Configuration:
C. How to retrieve a new client's token (locally)
D. Client validation flow
Client Validation Flow:
Validate token Configuration:
%dw 2.0 output application/json --- payload
Step 2: Deploy the OAuth 2.0 provider application to CloudHub
A. Deploying the application to CloudHub from Anypoint Studio
Step 3: Create a basic API Specification as an OAuth 2.0 Client application
A sample Anypoint Studio application is attached at the bottom of this article. oauth-2-client.jar shows what you should have at the end of Step 3.
A. Creating the API Specification in Design Center
#%RAML 1.0
title: YOUR_SPEC_NAME
securitySchemes:
oauth_2_0:
description: |
Mule OAuth 2.0.
type: OAuth 2.0
describedBy:
headers:
Authorization:
type: string
required: true
responses:
401:
description: |
Bad or expired token.
403:
description: |
Bad OAuth request.
settings:
authorizationUri: http://<CLOUDHUB_URL_OF_STUDIO_APP>.cloudhub.io/validate
accessTokenUri: http:// <CLOUDHUB_URL_OF_STUDIO_APP>.cloudhub.io/token
authorizationGrants: [client_credentials]
/test:
get:
securedBy: [oauth_2_0]
responses:
200:
body:
application/json:
examples: {"test":"success"}
B. Using your API Specification to create a OAuth 2.0 Client application in Anypoint Studio
Download RAML from Design Center UI:
C. Deploying the client application to CloudHub from Anypoint Studio
Step 4: Implement the OAuth 2.0 using API Manager
A. Managing your API Specification from Exchange in API Manager
App url Location:
Implementation URI Example:
B. Configuring your API implementation
API Implementation UI:
Consumer endpoint Configuration:
Populated URL for API Implementation:
C. Adding the OAuth 2.0 policy in API Manager
Access Token validation endpoint url:
D. Testing and validating your client application
Sample createClient Postman Request:
Request access token Response:
Successful Request:
That's it! You have now implemented your own OAuth 2.0 provider and created a client application that uses it. You can continue playing around with this in Anypoint Exchange and see what happens when you use invalid client_id or client_secret, create a new client_id and client_secret, and use an invalid token, or whatever the use case you want to test is!
Additionally, if you want to see all the clients you've created and valid tokens that have been generated, you can go to Runtime Manager, open the OAuth 2.0 provider application and click on Object Store found in the menu on the left.
----
For more information on the MuleSoft provided OAuth2 module, please see our documentation here.
001115866

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.