...
...
...
...
...
Table of Contents |
---|
Apiary |
|
|
mithril/users/{user_id}/authentication_factors | |
Scope | authentication_factor: |
write |
Purpose
Create
new
2FA item for user
.
Request parameters
- user_id
- type
Logic WS
- Validate
- $.token
- Get user by user_id
- Validate user id & user status
- Validate user `is_blocked` flag
- if is_blocked = TRUE
- return 4xx - "User blocked" (!!! TBD)
Validate existing 2FA item with $.type user
Code Block language sql SELECT * FROM authentication_factors AS 2FA
WHERE 2FA.user_id = $.user_id AND 2FA.
type =
$.type
- If
- key = 2FA.faсtor
- Get result of call `create OTP()` as `OTP_value`
- for 2FA.type = SMS - via SMS gateway API
- mobile phone = 2FA.factor
- SMS text = OTP_value
Internal logic for `create OTP()`
- Deactivate all active OTP items (NEW → CANCELED)
- not exist 2FA item with $.type
- Insert new record in `authentication_factors` with logical status = RESET
- user_id = $.user_id
- type = $.type
- factor = NULL
- is_active = TRUE
- inserted_at = now()
- Insert new record in `authentication_factors` with logical status = RESET
- not exist 2FA item with $.type
- update_at = now()
- Return 201
- If exist 2FA with $.type - return 409 error "authentication_factor with such type are exist"
Response
- 201 if 2FA item created successful
- 4xx in other case