returns the access token if the user id and the corresponding challenge are correct.
How to obtain a token
In order to obtain a token, the client must be authenticate by the service. This authentication is performed using a challenge (i.e. a unique string forged using the information contained in our database):
First the client requests a challenge from the server.
Using the user credentials (i.e. the password) the client tries to solve the challenge.
The client posts its response to the server.
The server effectively solves the challenge with the credentials stored in its database and compares the two responses.
If the responses match, the server returns a token.
This approach ensures a certain level of security because the password is not sent during the authentication process.
Each of the authentication steps is defined in the sections below.
Requesting the challenge
Description
In order to obtain a token, the client is responsible for requesting a challenge. This challenge can be requested using the following API endpoint:
Once fetched, the challenge must be solved using the user credentials. The expected solution is computed as follows:
First, concatenate the challenge string with the user password.
Then hash the concatenated string using a SHA256 hashing method.
Send back the hashed string along with the userId
response
The authentication service will responds depending on the solution passed. There are three cases:
The userId is incorrect
The solution is incorrect
Everything is correct
status
body
description
200 - OK
token
The authorization token
404 - Not Found
message
The userId provided is not known
400 - Bad Request
message
Incorrect password
500 - Internal Error
message
Something went wrong on our end
Once you receive the token, its TTL attribute is set to 1 day. Passed this date, the token will no longer authenticate your requests and our services will automatically respond with a401 UnauthorizedHTTP response.
In other words, it will be required to start again an authentication process to continue to use our services.
Here are some example responses:
// For a 200 - OK response, the body should look like:
{
"token": "aaa.bbb.ccc"
}
// For a 400 - Bad Request response:
{
"message": "Bad Request"
}
// For a 404 - Not Found response:
{
"message": "Not Found"
}
Here is the first method required for getting the token:
// performs a simple concatenation of the challenge and the passwordlet concatenatedString = [challenge, password].join('');//simply hash the resultlet solution =SHA256(concatenatedString);
// Using CryptoSwift podlet hashedChallenge ="\(challenge)\(password)".sha256()