def test_user_authorisation_url_equal_to_credentials(self): auth = Credentials(self.client_id, self.client_secret, self.redirect_uri) util = self._initialise() self.assertEqual(auth.user_authorisation_url(), util.user_authorisation_url())
class RefreshingCredentials: """ Client for retrieving automatically refreshing access tokens. Delegates to an underlying :class:`Credentials <tekore.auth.expiring.Credentials>` manager and parses tokens it returns into :class:`RefreshingToken`. Parameters ---------- client_id client id client_secret client secret redirect_uri whitelisted redirect URI sender request sender """ def __init__(self, client_id: str, client_secret: str, redirect_uri: str = None, sender: Sender = None): self._client = Credentials(client_id, client_secret, redirect_uri, sender) def request_client_token(self) -> RefreshingToken: """ Request a refreshing client token. Returns ------- RefreshingToken automatically refreshing client token """ token = self._client.request_client_token() return RefreshingToken(token, self._client) def user_authorisation_url(self, scope=None, state: str = None, show_dialog: bool = False) -> str: """ Construct an authorisation URL. Step 1/2 in authorisation code flow. User should be redirected to the resulting URL for authorisation. Parameters ---------- scope access rights as a space-separated list state additional state show_dialog force login dialog even if previously authorised Returns ------- str login URL """ return self._client.user_authorisation_url(scope, state, show_dialog) def request_user_token(self, code: str) -> RefreshingToken: """ Request a new refreshing user token. Step 2/2 in authorisation code flow. Code is provided as a URL parameter in the redirect URI after login in step 1. Parameters ---------- code code from redirect parameters Returns ------- RefreshingToken automatically refreshing user token """ token = self._client.request_user_token(code) return RefreshingToken(token, self._client) def refresh_user_token(self, refresh_token: str) -> RefreshingToken: """ Request an automatically refreshing user token with a refresh token. Parameters ---------- refresh_token refresh token Returns ------- RefreshingToken automatically refreshing user token """ token = self._client.refresh_user_token(refresh_token) return RefreshingToken(token, self._client)
def test_user_authorisation_url(self): c = Credentials('id', 'secret', 'uri') url = c.user_authorisation_url('scope', 'state', True) self.assertIn('scope=scope', url) self.assertIn('state=state', url) self.assertIn('show_dialog=true', url)