Performs the console authentication flow resulting in a stored token. It uses the credentials passed on instantiation. Returns True if succeeded otherwise False. :param list[str] requested_scopes: list of protocol user scopes to be converted by the protocol or
(self, *, requested_scopes: Optional[list] = None, redirect_uri: Optional[str] = None,
handle_consent: Callable = consent_input_token, **kwargs)
| 79 | return not self.con.token_backend.token_is_expired(username=self.con.username, refresh_token=True) |
| 80 | |
| 81 | def authenticate(self, *, requested_scopes: Optional[list] = None, redirect_uri: Optional[str] = None, |
| 82 | handle_consent: Callable = consent_input_token, **kwargs) -> bool: |
| 83 | """ Performs the console authentication flow resulting in a stored token. |
| 84 | It uses the credentials passed on instantiation. |
| 85 | Returns True if succeeded otherwise False. |
| 86 | |
| 87 | :param list[str] requested_scopes: list of protocol user scopes to be converted |
| 88 | by the protocol or scope helpers or raw scopes |
| 89 | :param str redirect_uri: redirect url configured in registered app |
| 90 | :param handle_consent: a function to handle the consent process by default just input for the token url |
| 91 | :param kwargs: other configurations to be passed to the |
| 92 | Connection.get_authorization_url and Connection.request_token methods |
| 93 | """ |
| 94 | |
| 95 | if self.con.auth_flow_type in ('authorization', 'public'): |
| 96 | consent_url, flow = self.get_authorization_url(requested_scopes, redirect_uri=redirect_uri, **kwargs) |
| 97 | |
| 98 | token_url = handle_consent(consent_url) |
| 99 | |
| 100 | if token_url: |
| 101 | result = self.request_token(token_url, flow=flow, **kwargs) |
| 102 | if result: |
| 103 | print('Authentication Flow Completed. Oauth Access Token Stored. You can now use the API.') |
| 104 | else: |
| 105 | print('Something go wrong. Please try again.') |
| 106 | |
| 107 | return result |
| 108 | else: |
| 109 | print('Authentication Flow aborted.') |
| 110 | return False |
| 111 | |
| 112 | elif self.con.auth_flow_type in ('credentials', 'password'): |
| 113 | return self.request_token(None, requested_scopes=requested_scopes, **kwargs) |
| 114 | |
| 115 | else: |
| 116 | raise ValueError('"auth_flow_type" must be "authorization", "public", "password" or "credentials"') |
| 117 | |
| 118 | def get_authorization_url(self, |
| 119 | requested_scopes: List[str], |