Customer authentication is used primarily for users that wants to access to login in web or app. Customers must login through customer type clients. For this, itβs necessary to use client_id and client_secret provided by Authn members.
When an user logs in, Authn uses client_id and client_secret of the client previously provided to retrieve the tenant associated with this client, and, then, it performs login itself, login checks the username and password of the customer in the database schema of the tenant previously found.
Customer Authentication flow
In this graph can be seen all the differents flows involved in token obtaining
To use this authentication method, a customer type client must be created. Clients are provided by the MasStack team after carefully auditing each use case so please contact your MasStack representative to obtain your client secrets.
How to obtain an access_token and refresh_token
Step 1 Obtain client_id and client_secret
Customers Type Clients can be provided by the MasStack
Owners. This team must be contacted in order to get those secrets.
A good practice is to store this parameters in different variables to have quickly access to this information because it will be needed in next steps.
Step 2 Create the HTTP Basic Auth header
In Postman, setting a basic header is as simple as setting Authorization to type Basic Auth, then you should pass the client_id as Username and client_secret as Password.
If you are not using Postman, you should:
Concatenate: client_id + β:β + client_secret
Encode all in base64
Step 3 Make a request to Authn
Once you have a variable with the HTTP Basic Auth header you should make a login request such as:
Name
Description
grant_type
parameter defines the OAuth2 flow that is going to be used; in this case password.
In case that client authentication and user authentication work fine Authn will respond with a couple of access_token and refresh_token:
Name
Description
access_token
is a signed JWT used by a user to authenticate himself against Istio’s service mesh.
refresh_token
is a signed JWT whose main goal is to obtain a new access_token without repeating customer authentication once the user has an active session.
expires_in
is the time that the access_token will be valid. Once it expires, the access_token won’t be valid and the user won’t be able to authenticate with it.
token_type
defines the type of the access_token that has been generated. This will normally be used in the Authorization header to indicate which kind of authentication has the request.
If the response includes an access token, you can use the access token to call a MasMovil API. (If the response does not include an access token, your JWT and token request might not be properly formed
When the access token expires, you should request another access_token with refresh_token grant
How to obtain new tokens with refresh_token flow
When an user logs in Authn a session is stored in redis. It means that when access_token expires client must use refresh_token obtained in the login to obtain a new couple of access_token and refresh_token, everything without involving the user and without using any kind of password, just client authentication.
To obtain new access_token and refresh_token you should make a request like:
Name
Description
grant_type
parameter defines the OAuth2 flow that is going to be used; in this case refresh_token.