Performs the device grant OAuth2.0 flow
| 3310 | |
| 3311 | |
| 3312 | class SSOTokenFetcher(BaseSSOTokenFetcher): |
| 3313 | """Performs the device grant OAuth2.0 flow""" |
| 3314 | |
| 3315 | # The device flow RFC defines the slow-down delay to be an additional |
| 3316 | # 5 seconds: |
| 3317 | # https://tools.ietf.org/html/draft-ietf-oauth-device-flow-15#section-3.5 |
| 3318 | _SLOW_DOWN_DELAY = 5 |
| 3319 | # The default interval of 5 is also defined in the RFC (see above link) |
| 3320 | _DEFAULT_INTERVAL = 5 |
| 3321 | _EXPIRY_WINDOW = 15 * 60 |
| 3322 | _GRANT_TYPE = 'urn:ietf:params:oauth:grant-type:device_code' |
| 3323 | |
| 3324 | def __init__( |
| 3325 | self, |
| 3326 | sso_region, |
| 3327 | client_creator, |
| 3328 | parsed_globals, |
| 3329 | cache=None, |
| 3330 | on_pending_authorization=None, |
| 3331 | time_fetcher=None, |
| 3332 | sleep=None, |
| 3333 | ): |
| 3334 | super().__init__( |
| 3335 | sso_region, |
| 3336 | client_creator, |
| 3337 | parsed_globals, |
| 3338 | cache, |
| 3339 | on_pending_authorization, |
| 3340 | time_fetcher, |
| 3341 | ) |
| 3342 | |
| 3343 | if sleep is None: |
| 3344 | sleep = time.sleep |
| 3345 | self._sleep = sleep |
| 3346 | |
| 3347 | def _register_client(self, session_name, scopes): |
| 3348 | register_kwargs = { |
| 3349 | 'clientName': self._generate_client_name(session_name), |
| 3350 | 'clientType': self._CLIENT_REGISTRATION_TYPE, |
| 3351 | } |
| 3352 | if scopes: |
| 3353 | register_kwargs['scopes'] = scopes |
| 3354 | response = self._client.register_client(**register_kwargs) |
| 3355 | expires_at = response['clientSecretExpiresAt'] |
| 3356 | expires_at = datetime.datetime.fromtimestamp(expires_at, tzutc()) |
| 3357 | registration = { |
| 3358 | 'clientId': response['clientId'], |
| 3359 | 'clientSecret': response['clientSecret'], |
| 3360 | 'expiresAt': expires_at, |
| 3361 | } |
| 3362 | if scopes: |
| 3363 | registration['scopes'] = scopes |
| 3364 | return registration |
| 3365 | |
| 3366 | def _registration( |
| 3367 | self, |
| 3368 | start_url, |
| 3369 | session_name, |
no outgoing calls