Skip to content

Instantly share code, notes, and snippets.

@rbmm
Created August 28, 2023 07:56
Show Gist options
  • Save rbmm/aec18b296956b33580c708faf7beb002 to your computer and use it in GitHub Desktop.
Save rbmm/aec18b296956b33580c708faf7beb002 to your computer and use it in GitHub Desktop.
сейчас у нас есть 2 формата ответов ( FAILURE / OK )
<responseHolder>
<status>FAILURE</status>
<error>
<code>%u</code>
<message>%s</message>
</error>
</responseHolder>
<responseHolder>
<status>OK</status>
<response>%DATA%</response>
</responseHolder>
и 3 формата запросов
/////////////////////////////////////////////////////////////////
// &serialNumber=%s используется только при регистрации
GET /api/v1/auth-service/policy.xml?resourceId=%u&userLogin=%s&rdp=%u&ip=%s[&serialNumber=%s]
ответ %DATA%
<status> 1(skip into the system) | 2(ask for otp) </status>
<token>
<id>%u</id>
<prepare> 0 (for SMART) | 1 ( for SMS/MAIL) </prepare>
[<qr>..only when SMART unregistered..</qr>]
</token>
[<message>..only when SMART unregistered..</message>]
или же в случае unregistered SMS/MAIL
<code>4002</code>
<message>[4002:c7IHawyrp1] User with Token (SMS) must be registered before authentication</message>
<code>4003</code>
<message>[4003:c7IHawyrp1] User with Token (MAIL) must be registered before authentication</message>
////////////////////////////////////////////////////////////////
// только для MAIL/SMS
POST /api/v1/auth-service/prepare.xml
resourceId=%u&tokenId=%u
ответ %DATA%
<tokenType> MAIL | SMS </tokenType>
<serialNumber> email | phone </serialNumber>
////////////////////////////////////////////////////////////////
// SMART/SMS/MAIL
POST /api/v1/auth-service/authenticate/token.xml
resourceId=%u&tokenId=%u&otp=%s&ip=%s
ответ %DATA%
<result>true | false</result>
***********************************************************************
так что для уже зареганных пользователей, ответ на GET api/v1/auth-service/policy.xml:
в случае SMART
<status>2</status>
<token>
<id>%u</id>
<prepare>0</prepare>
</token>
в случае SMS/MAIL
<status>2</status>
<token>
<id>%u</id>
<prepare>1</prepare>
</token>
разница только в <prepare> ( 0 или 1 )
вписать сюда PUSH элементарно (он вообще самый простой с моей стороны)
<status>1</status>
если OK или в случае ошибки
<code>102</code>
<message>[102:c7IHawyrp1] operation was not completed before the time-out period expired</message>
<code>1223</code>
<message>[1223:c7IHawyrp1] The operation was canceled by the user.</message>
или просто разрыв соединения через 30-60 сек.
это будет работать даже с уже существующим кодом.
не нужно STATUS_PENDING
просто сервер долго не возвращает ответ - пока пользователь не нажмёт у себя на телефоне что-то или истечёт timeout
***********************************************************************************
вот авто-регистрация, наиболее сложный случай. сейчас тип нового токена выбирается в интерфейсе сервера. если сохранить это,
то ответ на GET api/v1/auth-service/policy.xml нужно расширить до такого
<status> 1(skip into the system) | 2(ask for otp) | 3(not ask for otp) </status>
<token>
<id>%u</id>
<prepare> 0 (for SMART) | 1 ( for SMS/MAIL) </prepare>
[<qr>..only when SMART unregistered..</qr>]
</token>
[<message>..only when SMART unregistered..</message>]
тоесть добавляется ещё одно значение для <status> - 3 - не показывать поле для ввода OTP
тогда регистрация для PUSH будет выглядеть так
<status> 3 </status>
<token>
<id> %u </id>
<prepare> 0 </prepare>
<qr>...</qr>
</token>
<message>Download the Protectimus Smart PUSH ...</message>
я показываю QR и message и кнопку next ( без поля ввода OTP )
при нажатии на next - повторяю запрос GET api/v1/auth-service/policy.xml
и получаю
<status>1</status>
или FAILURE
для сравнения SMART регистрация
<status> 2 </status>
<token>
<id> %u </id>
<prepare> 0 </prepare>
<qr>...</qr>
</token>
<message>Download the Protectimus Smart OTP ...</message>
здесь status=2 (а не 3 как для PUSH)
я показываю QR и message, поле ввода OTP и кнопку next
при нажатии на next - уже запрос POST api/v1/auth-service/authenticate/token.xml
***************************************************************************************
если же делать выбор токена на клиенте ( самый сложный случай)
то наверерно такая схема.
в ответ на GET api/v1/auth-service/policy.xml
<code>4004</code>
<message>[4004:c7IHawyrp1] Choose the token type for enrollment</message>
мне нужно будет отобразить combobox с вариантами
[
MAIL
SMS
SMART
PUSH
]
кроме того в случае выбора MAIL или SMS показывается дополнительное поле для ввода email/phone number
и отправка такого (нового) запроса на сервер
PUT /api/v1/auth/token-enrollment.xml
type=%s&resourceId=%u&userLogin=%s&rdp=%u&ip=%s[&serialNumber=%s]
параметры такие же как в GET /api/v1/auth-service/policy.xml ( resourceId, userLogin, rdp, ip )
c добавлением параметра type ( MAIL | SMS | SMART | PUSH )
и serialNumber ( в случае с MAIL | SMS только )
и в ответ я уже получаю
<status> 1(skip into the system) | 2(ask for otp) | 3(not ask for otp) </status>
<token>
<id>%u</id>
<prepare> 0 (for SMART/PUSH) | 1 ( for SMS/MAIL) </prepare>
[<qr>..only when SMART/PUSH unregistered..</qr>]
</token>
[<message>..only when SMART/PUSH unregistered..</message>]
тоесть для SMS/MAIL
<status> 2 </status>
<token>
<id>%u</id>
<prepare> 1 </prepare>
</token>
для SMART
<status> 2 </status>
<token>
<id>%u</id>
<prepare> 0 </prepare>
<qr>...</qr>
</token>
<message>Download the Protectimus Smart OTP ...</message>
для PUSH
<status> 3 </status>
<token>
<id>%u</id>
<prepare> 0 </prepare>
<qr>...</qr>
</token>
<message>Download the Protectimus Smart PUSH ...</message>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment