ЕСОЗ - публічна документація
PIS. Patient login
Purpose
This WS is designed to authenticate user using any of the supported authentication methods.
Key points
This method should be reachable only by the eHealth authorization front-end application.
User is authenticated using different grant types: password, digital_signature, change_password, authorize_2fa_access_token, refresh_2fa_access_token, pis_auth.
Each grant type requires its specified set of fields with different validations.
Specification
Validate request
Validate client
Check
client_id
is submittedin case of error - return 422 ('can't be blank')
Check
client_id
exists in mithril databasein case of error - return 422 ('Invalid client id.')
Validate grant type
Check
grant_type
is submittedin case of error - return 422 ('Request must include grant_type.')
Check
grant_type
is one of the values: password, change_password, digital_signature, authorize_2fa_access_token, refresh_2fa_access_tokenin case of error - return 401 ('Grant type not allowed.')
Check
grant_type
is allowed to be issued by client (value exists inallowed_grant_types
setting for client)in case of error - return 401 ('Client is not allowed to issue login token.')
Validate ‘pis_auth’ grant type
Check
signed_content
andsigned_content_encoding
are submittedin case of error - return 422 ('can't be blank')
Check
signed_content
field is a valid base64 stringin case of error - return 422 ('Invalid signed content')
Check
signed_content_encoding
field value equals to 'base64'in case of error - return 422 ('is invalid')
Check digital signature is valid
in case of error - return 401 with digital signature validation error message
Check signed content is a valid JWT with
aud = mithril-login
in case of error - return 401 ('JWT is invalid.')
Validate scope
Check requested scope is allowed for client type
in case of error - return 422 ('Scope is not allowed by client type.')
Service logic
Search and create user
Step is applicable only for pis_auth grant type
Get drfo value from digital signature.
Search for existing user in mithril database,
users
table, with tax_id = drfo from digital signature and is_active = true.If user is found - check it is not blocked (is_blocked <> true)
in case blocked - return 401 ('User is blocked.').
in case not blocked - save
user_id
and proceed to p.3.
If user is not found - proceed to p.4.
Search for existing person in mpi database,
persons
table, with id = person_id from found user, status = active and is_active = truein case person not found - return 401 ('Person not found.')
in case person found - check its age is greater then no_self_auth_age global parameter
in case of error - return 401 ('Incorrect person age for such an action.')
in case persons age is correct - save
user_id
and proceed to PIS. Patient login | Generate token
Search for existing active person in mpi database with data from digital signature (drfo, last_name and given_name) using Active person search algorithm based on drfo value:
if drfo value equals to tax_id regexp (
^[0-9]{10}$
), field contains tax_id, use tax_id dataset for active person search,if drfo value equals to national_id number regexp (
^[0-9]{9}$
), field contains national_id number, use document dataset with type = 'NATIONAL_ID' for active person search,if drfo value contains at least one letter, perform reverse transliteration of field using existing algorithm (described here), then check that value equals to passport number regexp (
^((?![ЫЪЭЁ])([А-ЯҐЇІЄ])){2}[0-9]{6}$
), in case equals, field contains passport number, use document dataset with type = 'PASSPORT' for active person searchIf no active person was found - return 401 ('Person with tax id or document number not found.')
If more than one active person was found - return 401 ('It is impossible to uniquely identify the person.')
If one active person was found - proceed to p.5.
Check age of found active person is greater then no_self_auth_age global parameter
in case of error - return 401 ('Incorrect person age for such an action')
Search for existing user in mithril database,
users
table, with person_id = person_id from found person and is_active = true.If user is found - check it is not blocked (is_blocked <> true)
in case blocked - return 401 ('User is blocked.').
in case not blocked - update user, set tax_id = drfo from digital signature, set settings.trusted_source = true, save
user_id
and proceed to PIS. Patient login | Generate token
If user is not found - proceed to p.7.
Create user for active person in mithril database,
users
table, set:id = autogenerate uuid
settings = ‘{“trusted_source”: true}’
priv_settings = ‘{"login_hstr": [], "otp_error_counter": 0}’
inserted_at = now()
updated_at = now()
password_set_at = now()
tax_id =
drfo
value from digital signatureperson_id =
person_id
of person that was found on p.4.c.
Create global role for created user in mithril database,
global_user_roles
table, set:id = autogenerate uuid
user_id = user_id of user created on p.4
role_id = id of role with name ‘PATIENT’
inserted_at = now()
updated_at = now()
Generate token
Generate token with following logic:
If grant_type = pis_auth and not exists active authentication factor for user, generate token with name = ‘access_token’, scope = ‘app:authorize’ for user_id and client_id,
Save token to mithil database, tokens table, set:
id = token uuid
name = token name
value = hased token
expires_at = date and time when token will be expired in unix-time format
details = additional details of token (scopes, client_id, grant_type, applicant_user_id, applicant_patient_id), where
scope = requested scope list
client_id = client_id from request
grant_type = grant_type from request
applicant_user_id = user_id
applicant_person_id = person_id linked to user_id
user_id = uuid of user that requested token
inserted_at = now()
updated_at = now()
Find all active tokens of the same name for user_id and client_id, if found - expire them in mithril database, tokens table:
set expires_at = now()
Calculate next step:
if grant_type = pis_auth and not exists active authentication_method for user, then next_step = ‘REQUEST_APPS’
Render a response according to specification.
ЕСОЗ - публічна документація