Authenticate from a Non-Trusted Device
Steps
There are 2 steps in authenticating a Non-Trusted Device
Make a request from the Non-Trusted Device and wait for approval
Approve the request from a Trusted Device.
Step 1: Making an Authentication Request
Same as how it works with Authenticating from a Trusted Device, to authenticate a device, call the TrustedDeviceHelper.requestAuth
function. This will automatically detect whether the current device is a Trusted Device or not.
Event Name
The EVENT_NAME
should be filled by your app, according to what type of authentication event was requested. Example: LOGIN
event, TRANSACTION
event, UPDATE_PROFILE
event, etc.
Callback Class
The Callback.class
should be filled with the Activity to go to when the request is approved. For example, if this is a login request, then the Callback Activity can be your Dashboard class.
When an Authentication Event is requested TRUSTED_DEVICE
, there are 2 possible cases:
Case 1: The current device is a Trusted Device
You will be automatically approved if the request is coming from a Trusted Device. This is covered in Authenticate from a Trusted Device.
Case 2: The current device is NOT a Trusted Device
If the current device is not a Trusted Device, then it will create a pending event. This pending event will need to be approved by a Trusted Device. You should see a JSON result looking like:
The SDK will automatically show a prompt for the user to approve the event from a Trusted Device. The user then need to approve this request from their Trusted Device.
Step 2: How to approve a pending request from a Trusted Device
To check if there's a pending event for this user, you can call the getNewEvent
method from a Trusted Device.
In the future, your app that is installed in a Trusted Device will receive a notification and this method is invoked when the notification is opened.
For now, you should tell your user to press a button and invoke this method when they try to login from a non-trusted device.
The SDK will open a prompt in the Trusted Device asking if the user want to approve or reject the authentication request
In the prompt in the user's Non-Trusted Device (right picture), you can Customize the Prompt to ask them to press a specific button in the Trusted Device to invoke the prompt on the left.
Receiving the result and check if the request was approved
In the non-trusted device where the user is trying to log in, you'll receive the result in the callback class that your specified.
Case 1: The request is approved
When the request is approved, the SDK will automatically redirect to your Callback Class. In the callback class, you should handle the response from Cotter
Handle the response in your callback class
You'll receive a response in the form of a TrustedDeviceResponse
object.
When this authentication request is approved, you'll receive an access token in the String Response. Send this access token to your backend to validate it:
Verifying JWT TokensCase 2: The request is rejected
If the request is not approved for 1 minute, the prompt in the Non-Trusted Device will show an error message. The prompt will not show an error immediately when the Trusted Device denied the request, i.e. there is no difference between rejection and no response from the Trusted Device.
In this case, the onError
function that you passed in earlier will be called with an error message of Event is not approved
.
Last updated