-------------------- Calls and returns data from API: auth/token, which validates signed challenge token and provides new Access_Token and Refresh_Token. Can optionally supply a keymanager object, instead of the public_key and signed_challenge_token. Returns:
(self, user_id:str, challange_token:str, signed_challange_token:str='', public_key:str=None, keymanager:object=None, scheme:str = "ed25519")
| 449 | |
| 450 | |
| 451 | def auth_token(self, user_id:str, challange_token:str, signed_challange_token:str='', public_key:str=None, keymanager:object=None, scheme:str = "ed25519"): |
| 452 | """-------------------- |
| 453 | Calls and returns data from API: auth/token, which validates signed challenge token and provides new Access_Token and Refresh_Token. |
| 454 | Can optionally supply a keymanager object, instead of the public_key and signed_challenge_token. |
| 455 | |
| 456 | Returns: |
| 457 | bool: Success flag (True/False) indicating the api call worked as expected. |
| 458 | object: Response information from the Space and Time network, as list or dict(json). |
| 459 | """ |
| 460 | if keymanager: |
| 461 | try: |
| 462 | public_key = keymanager.public_key_to(keymanager.ENCODINGS.BASE64) |
| 463 | signed_challange_token = keymanager.sign_message(challange_token) |
| 464 | except Exception as ex: |
| 465 | return False, {'error':'keymanager object must be of type SXTKeyManager, if supplied.'} |
| 466 | |
| 467 | dataparms = { "userId": user_id |
| 468 | ,"signature": signed_challange_token |
| 469 | ,"authCode": challange_token |
| 470 | ,"key": public_key |
| 471 | ,"scheme": scheme} |
| 472 | success, rtn = self.call_api(endpoint='auth/token', auth_header=False, data_parms=dataparms) |
| 473 | if success: |
| 474 | self.__settokens__(rtn['accessToken'], rtn['accessTokenExpires'], rtn['refreshToken'], rtn['refreshTokenExpires']) |
| 475 | return success, rtn if success else [rtn] |
| 476 | |
| 477 | |
| 478 | def token_refresh(self, refresh_token:str): |