emolero's picture
Upload folder using huggingface_hub
ab74ec2 verified
|
Raw
History Blame Contribute Delete
9.18 kB

Overview

One Time Password SMS API is used to send short-lived OTPs (one time passwords) to a phone number via SMS and validate it afterwards, in order to provide a proof of possession of the phone number.

1. Introduction

One Time Password SMS API performs real-time checks to verify that the user possessed the device that carries the indicated mobile phone number. It provides a frequent method of verifying possession of the device by delivering an OTP (one-time password) through SMS and validating it afterwards.

SMS OTP (one time password) is a secure method for providing one-time access to an application or performing a single transaction. OTP is most effective and legitimate for a single transaction, unlike user-generated passwords. It is a secure authentication method where a text containing a unique alphanumeric or numeric code is sent to a mobile number (MSISDM).

The recipient then uses this code or password as an additional layer of security to login to a service, website or app.

2. Quick Start

The usage of the API is based on several resources.

Before starting to use the API, the developer needs to know about the below specified details:

API service endpoint

Two endpoints are defined in One Time Password SMS API:

  • POST /one-time-password-sms/v0/send-code : Sends an SMS with the desired message and an OTP code to the received phone number
  • POST /one-time-password-sms/v0/validate-code : Verifies the received code as input is valid for the given authenticationId.

Authentication

Security access token based on two-legged authentication is required for this API with dedicated scope.

Sample API invocations are presented in Section 4.6.

3. Authentication and Authorization

One Time Password SMS API uses OAUTH 2.0 client credentials grant which is applicable for server to server use cases involving trusted partners or clients without any protected user data involved. [1]

4. API Documentation

4.1 API Version

0.1.0

4.2 Details

4.2.1 Endpoint Definition

Following table defines API endpoints of exposed REST based for One Time Password SMS API operations.

Endpoint Operation Description
POST /one-time-password-sms/v0/send-code Request to send an OTP code Create request in order to send an OTP code with the given message to a mobile phone number
POST /one-time-password-sms/v0/validate-code Request to validate an OTP code Create a request to validate an OTP code for the given authenticationId

One Time Password SMS API Resource Operations:


Request code
HTTP Request
POST /one-time-password-sms/v0/send-code
Query Parameters
No query parameters are defined.
Path Parameters
No path parameters are defined.
Request Body Parameters
phoneNumber: A phone number belonging to the user. 'E164 with +' format.
message: Message template used to compose the content of the SMS sent to the phone number. It must include the following label indicating where to include the short code {{code}}.


Response
200: OK
Response body:
authenticationId : Unique id of the verification attempt the code belongs to.
400: INVALID_ARGUMENT
401: UNAUTHENTICATED
403: PERMISSION_DENIED
403: ONE_TIME_PASSWORD_SMS.MAX_OTP_CODES_EXCEEDED
403: ONE_TIME_PASSWORD_SMS.PHONE_NUMBER_NOT_ALLOWED
403: ONE_TIME_PASSWORD_SMS.PHONE_NUMBER_BLOCKED
404: NOT_FOUND
405: METHOD_NOT_ALLOWED
406: NOT_ACCEPTABLE
415: UNSUPPORTED_MEDIA_TYPE
429: TOO_MANY_REQUESTS
500: INTERNAL
503: UNAVAILABLE
504: TIMEOUT


Validate code
HTTP Request
POST /one-time-password-sms/v0/validate-code
Query Parameters
No query parameters are defined.
Path Parameters
No path parameters are defined.
Request Body Parameters
authenticationId: Unique id of the verification attempt the code belongs to.
code: Temporal, short code to be validated.


Response
204: The OTP was successfully validated
400: INVALID_ARGUMENT
400: ONE_TIME_PASSWORD_SMS.VERIFICATION_EXPIRED
400: ONE_TIME_PASSWORD_SMS.VERIFICATION_FAILED
400: ONE_TIME_PASSWORD_SMS.INVALID_OTP
401: UNAUTHENTICATED
403: PERMISSION_DENIED
404: NOT_FOUND
405: METHOD_NOT_ALLOWED
406: NOT_ACCEPTABLE
415: UNSUPPORTED_MEDIA_TYPE
429: TOO_MANY_REQUESTS
500: INTERNAL
503: UNAVAILABLE
504: TIMEOUT


4.3 Errors

Since CAMARA One Time Password SMS API is based on REST design principles and blueprints, well defined HTTP status codes and families specified by community are followed [2].

Details of HTTP based error/exception codes for One Time Password SMS API are described in Section 4.2 of each API REST based method. Following table provides an overview of common error names, codes, and messages applicable to One Time Password SMS API.

No Error Name Error Code Error Message
1 400 INVALID_ARGUMENT "Client specified an invalid argument, request body or query param"
2 400 ONE_TIME_PASSWORD_SMS.VERIFICATION_EXPIRED "The authenticationId is no longer valid"
3 400 ONE_TIME_PASSWORD_SMS.VERIFICATION_FAILED "The maximum number of attempts for this authenticationId was exceeded without providing a valid OTP"
4 400 ONE_TIME_PASSWORD_SMS.INVALID_OTP "The provided OTP is not valid for this authenticationId"
5 401 UNAUTHENTICATED "Request not authenticated due to missing, invalid, or expired credentials"
6 403 PERMISSION_DENIED "Client does not have sufficient permissions to perform this action"
7 403 ONE_TIME_PASSWORD_SMS.MAX_OTP_CODES_EXCEEDED "Too many OTPs have been requested for this MSISDN. Try later."
8 403 ONE_TIME_PASSWORD_SMS.PHONE_NUMBER_NOT_ALLOWED "Phone_number can't receive an SMS due to business reasons in the operator"
9 403 ONE_TIME_PASSWORD_SMS.PHONE_NUMBER_BLOCKED "Phone_number is blocked to receive SMS due to any blocking business reason in the operator"
10 404 NOT_FOUND "A specified resource is not found"
11 405 METHOD_NOT_ALLOWED "The requested method is not allowed/supported on the target resource"
12 406 NOT_ACCEPTABLE "The server can't produce a response matching the content requested by the client through Accept-* headers"
13 415 UNSUPPORTED_MEDIA_TYPE "The server refuses to accept the request because the payload format is in an unsupported format"
14 429 TOO_MANY_REQUESTS "Either out of resource quota or reaching rate limiting"
15 500 INTERNAL "Server error"
16 503 UNAVAILABLE "Service unavailable"
17 504 TIMEOUT "Request timeout exceeded. Try later."

4.4 Policies

N/A

4.5 Code Snippets


Snippets elaborates REST based API call with "*curl"* to request

Please note, the credentials for API authentication purposes need to be adjusted based on target security system configuration.

Snippet 1. Request code
curl -X 'POST' https://sample-base-url/one-time-password-sms/v0/send-code
-H 'accept: application/json'
-H 'Content-Type: application/json'
-H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbG...."
-d '{ "phoneNumber": "+346661113334",
"message": "{{code}} is your short code to authenticate with Cool App via SMS"}'
The response will be:
200
-d '{ "authenticationId": "ea0840f3-3663-4149-bd10-c7c6b8912105" }'

Snippet 2. Validate code
curl -X 'POST' https://sample-base-url/one-time-password-sms/v0/validate-code
-H 'accept: application/json'
-H 'Content-Type: application/json'
-H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbG...."
-d '{ "authenticationId": "ea0840f3-3663-4149-bd10-c7c6b8912105",
"code": "AJY3"}'
The response will be:
204

4.6 FAQs

(FAQs will be added in a later version of the documentation)

4.7 Terms

N/A

4.8 Release Notes

N/A

References

[1] CAMARA Commonalities : Authentication and Authorization Concept for Service APIs
[2] HTTP Status codes spec