Logging in using QR

Instead of asking a user for their username and password, you can let them log in to your website by showing them a QR code they need to scan. In this scenario, you will see how to implement this process.

How does it work?

The process for logging in passwordless, with a QR code can be seen below.

  1. You redirect the user to the login page.
  2. User chooses to login with QR.
  3. A screen with QR code along with a countdown bar is shown.
  4. User opens the mobile app and scans the QR code.
  5. User is logged in into the web application.

You know the user is logged in as soon as you reach step 5, but you need the access token to call other API endpoints.

What APIs do you need?

In order to achieve the flow described above, the authentication API is required, and the needed modules are QrCodeAuthentication and QrCodeScanRequired.

An example of an authentication request for issuing a QR code to authenticate the user with can be seen below:

CURL
Copy

The response of this API contains the QR code, along with an attribute which specifies for how long the QR code is valid.

JSON
Copy
Attribute NameAttribute Description
nextModuleSpecifies the next module to be used in order to continue with the authentication process. If next module is Success, it means that you are authenticated.
additionalInformation.validityPeriodIndicates for how long the QR code is valid. The returned value is in seconds, and if the user scans the QR code after validityPeriod, the request will fail.
additionalInformation.qrCodeRepresents the base64 encoded value of the QR code.
additionalInformation.qrCodeTrackIdRandom value generated by the backend server, which needs to be sent in subsequent authentication requests, either as a cookie or in the payload.
additionalInformation.nonceRepresents a random value, which has to be sent in subsequent authentication requests for verifying if the scanning of the QR has been performed.

Once you have a QR code, you can show that to the user, along with a timer filled with the value from the response.

Now that the QR code is available to the end-user, you have to send regular requests to verify if the user scanned the QR code. In order to do so, you have to call the API described below:

CURL
Copy

Using the data returned from the previous API, this API can be called regularly, to verify if the user managed to scan the QR code. We recommend calling this API at fixed time intervals, from two to three seconds, in order to not overload the server with unnecessary requests, since it is less probable that the user will be able to open the app and scan the QR code in within a second. If the user did not manage to scan the QR code in time, the API will respond with a 400 bad request with following error response:

JSON
Copy

This is an error from which you cannot recover, but what you can do instead is to offer a possibility to the user to generate a new QR code. If the user successfully scans the QR code, the response from below will be returned:

JSON
Copy
Attribute NameAttribute description
nextModuleSpecifies the next module to be used in order to continue with the authentication process. If next module is Success, it means that you are authenticated.
tokenRepresents the single sign on token.
jwtTokenA JWT token with details about the authenticated user.
oauth2TokenOauth2 access token, which can be used to access different APIs.
userDataDepending on the authentication module used, at the end of the process, this attribute may contain different properties.
settingsThe object contains a set of configured properties, which helps calling applications to redirect the user to a configured page upon successful authentication.
Type to search, ESC to discard
Type to search, ESC to discard
Type to search, ESC to discard
  Last updated by Ruud Vroon