Following the rfc, this will route the device request accordingly and raise required errors. Remember that unlike other auth flows, the device if polling this endpoint once every "interval" amount of seconds.
(self, request, device_code)
| 223 | |
| 224 | @rate_limit # this will raise the SlowDownError |
| 225 | def device_flow_token_response(self, request, device_code): |
| 226 | """ |
| 227 | Following the rfc, this will route the device request accordingly and raise |
| 228 | required errors. |
| 229 | |
| 230 | Remember that unlike other auth flows, the device if polling this endpoint once |
| 231 | every "interval" amount of seconds. |
| 232 | """ |
| 233 | # using device_code arg to retrieve the correct device object instance |
| 234 | device = Device |
| 235 | |
| 236 | if device.status == device.DeviceFlowStatus.AUTHORIZATION_PENDING: |
| 237 | raise AuthorizationPendingError() |
| 238 | |
| 239 | # If user clicked "deny" in the /approve-deny page endpoint. |
| 240 | # the device gets set to 'authorized' in /approve-deny and /device checks |
| 241 | # if someone tries to input a code for a user code that's already been authorized |
| 242 | if device.status == device.DeviceFlowStatus.DENIED: |
| 243 | raise AccessDenied() |
| 244 | |
| 245 | url, headers, body, status = self.server.create_token_response(request) |
| 246 | |
| 247 | access_token = json.loads(body).get("access_token") |
| 248 | |
| 249 | device.status = device.EXPIRED |
| 250 | |
| 251 | # return access_token in a http response |
| 252 | return access_token |
| 253 | |
| 254 | # Example of how token endpoint could handle the token creation depending on |
| 255 | # the grant type during a POST to /token. |
no test coverage detected