Mule 4 TOTP Connector to Generate Code Compatible to Google Authentication
A software architect and DZone Core member gives a quick tutorial on how to connect Google Authenticate to a MuleSoft application using a TOTP connector.
Join the DZone community and get the full member experience.Join For Free
- TOTP Connector Details
- Usage Scenarios
In this article, we'll enable a MuleSoft application to validate am authentication code generated by Google Authentication where a user's account is registered based on a key.
TOTP Connector Details
While accepting the input key as an input, it will be decoded with the
After it's decoded with
Base32, it creates a key that has the
crypto type and generates a six digit time-based code.
A connector is useful for authenticating a Google Authentication code with MuleSoft integration to authorize an application to access protected resources.
Register an Account in Google Authentication
Follow the below steps.
Step 1: Add an account.Step 2: Choose the 'Enter account details' option and enter an account name and key as shown in the below screenshot:
Step 3: Click on the 'Add' option to register an account in the Google Authentication app. Once we're successfully registered, we should see an auto-generated number in the app. This number will be automatically updated after a given amount of time.
Now our account is registered in the Google authentication app. The next step to install a custom TOTP connector in Anypoint Studio and include it in our flow to validate it. The code generated by MuleSoft's flow should be equal to the code generated in the Google Authentication app.
After completing the code for the TOTP Connector, build and install the connector in Anypoint Studio with the following steps.
Build and Install in a Local Maven Repository
Execute the below command:
We can see that build is successful and installed in the local Maven repository.
Add a TOTP Connector Dependency to Your MuleSoft Application
Design a MuleSoft Flow
In the below code block, we have configured our MuleSoft flow and are receiving a key value from the payload's
Now, test and verify that the codes generated by the Google Authentication App are the same.
Code Generated by MuleSoft Flow
Code Generate by Google Authentication App for the Same Key and Specific Time Duration
Here, we can find both codes are the same for the same time interval and key.
Opinions expressed by DZone contributors are their own.