|
| 1 | +### Scenario 8: Device authorization flow |
| 2 | + |
| 3 | +The application goes through the following steps to complete app-native authentication using the device authorization flow. |
| 4 | + |
| 5 | +- **Step 1**: Get the required codes. |
| 6 | + |
| 7 | + The app initiates a login request to the device authorization endpoint. |
| 8 | + |
| 9 | + !!! note |
| 10 | + The response contains the `user_code` and `device_code` required for the client device. |
| 11 | + |
| 12 | + === "Request (`/device_authorize`)" |
| 13 | + |
| 14 | + ```bash |
| 15 | + curl --location '{{api_oauth2_path}}/device_authorize/' |
| 16 | + --header 'Accept: application/json' |
| 17 | + --header 'Content-Type: application/x-www-form-urlencoded' |
| 18 | + --data-urlencode 'client_id=XWRkRNkJDeTiR5MwHdXROGiJka' |
| 19 | + --data-urlencode 'scope=openid profile' |
| 20 | + ``` |
| 21 | + === "Response (`/device_authorize`)" |
| 22 | + |
| 23 | + ```json |
| 24 | + { |
| 25 | + "user_code": "s2DqSNK", |
| 26 | + "device_code": "d3fe0db1-2334-48fa-b7d9-821ecfad10d5", |
| 27 | + "interval": 5, |
| 28 | + "verification_uri": "{{api_oauth2_path}}/authenticationendpoint/device.do", |
| 29 | + "verification_uri_complete": "{{api_oauth2_path}}/authenticationendpoint/device.do?user_code=s2DqSNK", |
| 30 | + "expires_in": 600 |
| 31 | + } |
| 32 | + ``` |
| 33 | + |
| 34 | +- **Step 2**: Authorize the client device. |
| 35 | + |
| 36 | + The app on the client device calls the device endpoint with the `user_code` to initiate authentication. |
| 37 | + |
| 38 | + !!! note |
| 39 | + Set `response_mode=direct` to initiate app-native authentication. |
| 40 | + |
| 41 | + === "Request (`/device`)" |
| 42 | + |
| 43 | + ```bash |
| 44 | + curl --location '{{api_oauth2_path}}/device/' |
| 45 | + --header 'Accept: application/json' |
| 46 | + --header 'Content-Type: application/x-www-form-urlencoded' |
| 47 | + --data-urlencode 'user_code=s2DqSNK' |
| 48 | + --data-urlencode 'response_mode=direct' |
| 49 | + ``` |
| 50 | + === "Response (`/device`)" |
| 51 | + |
| 52 | + ```json |
| 53 | + { |
| 54 | + "flowId": "95339089-72d1-4825-80fe-ab7864f4943b", |
| 55 | + "flowStatus": "INCOMPLETE", |
| 56 | + "flowType": "AUTHENTICATION", |
| 57 | + "nextStep": { |
| 58 | + "stepType": "AUTHENTICATOR_PROMPT", |
| 59 | + "authenticators": [ |
| 60 | + { |
| 61 | + "authenticatorId": "QmFzaWNBdXRoZW50aWNhdG9yOkxPQ0FM", |
| 62 | + "authenticator": "Username & Password", |
| 63 | + "idp": "LOCAL", |
| 64 | + "metadata": { |
| 65 | + "i18nKey": "authenticator.basic", |
| 66 | + "promptType": "USER_PROMPT", |
| 67 | + "params": [ |
| 68 | + { |
| 69 | + "param": "username", |
| 70 | + "type": "STRING", |
| 71 | + "order": 0, |
| 72 | + "i18nKey": "username.param", |
| 73 | + "displayName": "Username", |
| 74 | + "confidential": false |
| 75 | + }, |
| 76 | + { |
| 77 | + "param": "password", |
| 78 | + "type": "STRING", |
| 79 | + "order": 1, |
| 80 | + "i18nKey": "password.param", |
| 81 | + "displayName": "Password", |
| 82 | + "confidential": true |
| 83 | + } |
| 84 | + ] |
| 85 | + }, |
| 86 | + "requiredParams": [ |
| 87 | + "username", |
| 88 | + "password" |
| 89 | + ] |
| 90 | + } |
| 91 | + ] |
| 92 | + }, |
| 93 | + "links": [ |
| 94 | + { |
| 95 | + "name": "authentication", |
| 96 | + "href": "{{authn_path}}", |
| 97 | + "method": "POST" |
| 98 | + } |
| 99 | + ] |
| 100 | + } |
| 101 | + ``` |
| 102 | + |
| 103 | +- **Step 3**: Carry the `flowId` received in the above response and request the `/authn` endpoint for username & password authentication. |
| 104 | + |
| 105 | + === "Request (`/authn`)" |
| 106 | + |
| 107 | + ```bash |
| 108 | + curl --location '{{authn_path}}' |
| 109 | + --header 'Content-Type: application/json' |
| 110 | + --data '{ |
| 111 | + "flowId": "95339089-72d1-4825-80fe-ab7864f4943b", |
| 112 | + "selectedAuthenticator": { |
| 113 | + "authenticatorId": "QmFzaWNBdXRoZW50aWNhdG9yOkxPQ0FM", |
| 114 | + "params": { |
| 115 | + "username": "username", |
| 116 | + "password": "password" |
| 117 | + } |
| 118 | + } |
| 119 | + }' |
| 120 | + ``` |
| 121 | + |
| 122 | + === "Response (`/authn`)" |
| 123 | + |
| 124 | + ```json |
| 125 | + { |
| 126 | + "flowStatus": "SUCCESS_COMPLETED", |
| 127 | + "authData": { |
| 128 | + "app_name": "Mobile App" |
| 129 | + } |
| 130 | + } |
| 131 | + ``` |
| 132 | + |
| 133 | +- **Step 4**: Once the user completes authentication, the app on the client device polls the token endpoint with the `device_code` to obtain the access token. |
| 134 | + |
| 135 | + === "Request (`/token`)" |
| 136 | + |
| 137 | + ```bash |
| 138 | + curl --location '{{api_oauth2_path}}/token/' |
| 139 | + --header 'Content-Type: application/x-www-form-urlencoded' |
| 140 | + --data-urlencode 'grant_type=urn:ietf:params:oauth:grant-type:device_code' |
| 141 | + --data-urlencode 'device_code=d3fe0db1-2334-48fa-b7d9-821ecfad10d5' |
| 142 | + --data-urlencode 'client_id=XWRkRNkJDeTiR5MwHdXROGiJka' |
| 143 | + ``` |
| 144 | + |
| 145 | + === "Response (`/token`)" |
| 146 | + |
| 147 | + ```json |
| 148 | + { |
| 149 | + "access_token": "74d610ab-7f4a-3b11-90e8-279d76644fc7", |
| 150 | + "refresh_token": "fdb58069-ecc7-3803-9b8b-6f2ed85eff19", |
| 151 | + "token_type": "Bearer", |
| 152 | + "expires_in": 3600 |
| 153 | + } |
| 154 | + ``` |
0 commit comments