DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Software Design and Architecture
  3. Security
  4. OAuth in Mule and Mule Secure Token Service

OAuth in Mule and Mule Secure Token Service

In this article, we explore some of the topics related to securing your MuleSoft application, like Mule's OAuth support and Mule's Secure Token Service.

Rajesh Kumar user avatar by
Rajesh Kumar
·
Jan. 15, 18 · Tutorial
Like (3)
Save
Tweet
Share
9.37K Views

Join the DZone community and get the full member experience.

Join For Free

What Is OAuth?

OAuth is an open standard for access delegation and has become the current industry standard protocol for authorization, especially to expose APIs to the external world in a secure way.

Check out their website for more information and to understand how it works.

Mule OAuth Service

Mule provides two elements to work with the OAuth protocol. In this post, we'll look at its configuration and some examples of how to validate and register the client as part of a Mule app.

As mentioned above, the OAuth framework allows you to access a resource in a secure way and gives you the ability to provide:

  • Permissions to consumers of your API with limited access to secure data, like read-only access, limited data access, etc.

  • No need to disclose the access credentials to the consumer (we will talk about this later in the article, as part of Mule Secure Token Service).

  • Retain the authority to revoke consumers' permissions to access your API at any time.

Mule provides two main elements to enable OAuth, those are:

  • The provider and config elements, which contain the settings for the provider, such as security providers, login page details, and other settings, and mainly describes the resource's access and scopes.

Image title

Generally, the OAuth provider generates or issues client IDs or secrets.

As a part of Mule, the OAuth provider module does not generate client IDs or secrets. In Mule, the OAuth provider is responsible for accepting and storing the client ID and secrets.

The provider-config element enables the configuration for OAuth (consider this as a global element):

  • provider-<<operation>> will enable the operations .

  • validate - Validates the tokens, confirming that the client presents the correct scopes to access the resource.

Image title

Here's some example code to configure for validation in a Mule XML file:

<oauth2-provider:validate scopes="READ_PROFILE" config-ref="oauth2Provider" doc:name="OAuth provider module"/>

Create Client - This operation allows Mule to accept and store the client data, i.e., ID, secret, redirection URI, scope, and grant types, in the client store. Generally, this client store will be a database or default object store.

Image title

In Mule, default storage is a persistent object store. So, you'll need to define the user service under the authentication manager in the flow for the storage.

In below configuration, authentication-provider defines the database for the users and the number of users can be added using the ss:user element.

<spring:beans>
        <ss:authentication-manager id="resourceOwnerAuthenticationManager"> 
            <ss:authentication-provider>
                <ss:user-service id="resourceOwnerUserService">
                    <ss:user name="user" password="password" authorities="RESOURCE_OWNER"/>
                </ss:user-service>
            </ss:authentication-provider>
        </ss:authentication-manager>
</spring:beans>

The supported storage options offered directly by Mule are jdbc, ldap, password encoder, and fixed no of users (fixed no of users is shown in above configuration).

Image title

Mule Secure Token Service is Mule's OAuth 2.0 solution for MuleSoft. Check this link to understand its usage and enablement. It's a very interesting tool that provides a solution for APIs and apps hosted by CloudHub.

security authentication

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How To Create and Edit Excel XLSX Documents in Java
  • Mr. Over, the Engineer [Comic]
  • Real-Time Stream Processing With Hazelcast and StreamNative
  • Express Hibernate Queries as Type-Safe Java Streams

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: