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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

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

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Create Proxy Application for Mule APIs
  • Keep Your Application Secrets Secret
  • Essential Mobile App Security Tips for Coders in 2023: Make Your App Unhackable
  • API Security Is Finally Gaining Attention That it Deserves

Trending

  • Beyond Linguistics: Real-Time Domain Event Mapping with WebSocket and Spring Boot
  • A Modern Stack for Building Scalable Systems
  • Solid Testing Strategies for Salesforce Releases
  • Streamlining Event Data in Event-Driven Ansible
  1. DZone
  2. Data Engineering
  3. Databases
  4. Secure Mule API by Auth0 (External Identity Provider)

Secure Mule API by Auth0 (External Identity Provider)

In this article, take a look at how to secure a Mule API with Auth0.

By 
Mukesh Thakur user avatar
Mukesh Thakur
DZone Core CORE ·
Apr. 28, 20 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
16.0K Views

Join the DZone community and get the full member experience.

Join For Free

JWT-Based API Authentication Using Auth0 and Mulesoft

Web API security is concerned with the transfer of data through APIs that are connected to the internet. Auth0 is an external identity provider that enables systems to give access to REST API resources (exposes via MuleSoft) without having to share passwords.

What Is an Identity Provider?

It is a service that creates and maintains identity information and then provides authentication services to your applications. Identity Providers can significantly reduce sign-in and registration friction, which allows your users to easily access applications without needing to create new passwords or remember usernames 

Mulesoft

Provides exceptional business agility to companies by connecting applications, data, and devices, both on-premises and in the cloud with an API-led approach. By leveraging Anypoint Platform.

Auth0

Provides a flexible and drop-in solution to add authentication and authorization services to the applications.

M2M Token-Based Approach to Secure API

API developed in MuleSoft can be secured using machine-to-machine (M2M) applications, such as CLIs, daemons, or services running on our back-end, the system authenticates and authorizes the app rather than a user. For this scenario, typical authentication schemes like username + password or social logins don't make sense. Instead, M2M apps use the Client Credentials Flow (defined in OAuth 2.0 RFC 6749, section 4.4), in which they pass along their Client ID and Client Secret to authenticate themselves and get a token.

Account Setup in Auth0

  • Create an account in Auth0
  • Login into the account using account credential
  • Click the CREATE button to create the application


  • Name the application, choose application type as machine to machine.


  • Add API name, select scope, and click on Authorize


Note: Scopes depends on need

  • Copy the client_id and client_secret of the application that would need when we generate security token 

  • Scroll down to the bottom and select advanced settings. In the Grant Type, make sure only Client Credentials is selected. Click Save Changes to save the changes.

Test Auth0 configuration

  • Click on Test and copy code snippet and generate token

POST: https://dev-auth0-41u.auth0.com/oauth/token 

JSON
 




xxxxxxxxxx
1


 
1
{
2
    "client_id":"L0FsYtDZBBXCw0tk64gwJ1br4LzX5E27",
3
    "client_secret":"ScNEfHMCtaxkbLRWznc6Zc2dxqF-sVhwUdLQmiXqc6mIXoAXEPkk-nBi_laQKZi2",
4
    "audience":"https://dev-auth0-41u.auth0.com/api/v2/",
5
    "grant_type":"client_credentials"
6
    
7
}



Configuration in Anypoint Platform

JWT Policy in API Manager of Anypoint Platform

To create a policy in API Manager, an API must be created from RAML/OAS/SOAP or available in exchange to import

  • Login to Anypoint Platform and select API Manager
  • Click on Manage API from Exchange


  • Search API name, select Asset type, and check mule version and click Save


  • On success, API page display and Copy Autodiscovery(API ID). It would be used in actual implementation flow to refer policy from Mule instance.


  • Click on Policies > Appy New policy > Select policy


  • Configure JWT Policy


Configure Autodiscovery in API Implementation

  • Add API ID, which copied from API manager, and select the flow on which policy to be applied


  • Deploy API instance to CloudHub


  • Verify Policy in API Manager. If status turns to green, it means policy has been applied


Test API 

Generate Auth token as discussed in the above steps

  1. Call Get : authdemo-order-api.us-e2.cloudhub.io/api/orders & pass bearer token as Authorization 
  2. You would get API response

Summary

This demonstration shows the way to secure your API. We can control a user to access the particular APIs and manage the client by creating a contract in API Manager. We are going to publish those demonstrations soon, so stay tuned for further extension.

Repository

  1. Source code: mule application
  2. API specification: RAML
API security application

Published at DZone with permission of Mukesh Thakur. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Create Proxy Application for Mule APIs
  • Keep Your Application Secrets Secret
  • Essential Mobile App Security Tips for Coders in 2023: Make Your App Unhackable
  • API Security Is Finally Gaining Attention That it Deserves

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!