Authorization server that handles Authorization Endpoint and Token Endpoint. :param scopes_supported: A list of supported scopes by this authorization server.
| 16 | |
| 17 | |
| 18 | class AuthorizationServer(Hookable): |
| 19 | """Authorization server that handles Authorization Endpoint and Token |
| 20 | Endpoint. |
| 21 | |
| 22 | :param scopes_supported: A list of supported scopes by this authorization server. |
| 23 | """ |
| 24 | |
| 25 | def __init__(self, scopes_supported=None): |
| 26 | super().__init__() |
| 27 | self.scopes_supported = scopes_supported |
| 28 | self._token_generators = {} |
| 29 | self._client_auth = None |
| 30 | self._authorization_grants = [] |
| 31 | self._token_grants = [] |
| 32 | self._endpoints = {} |
| 33 | self._extensions = [] |
| 34 | |
| 35 | def query_client(self, client_id): |
| 36 | """Query OAuth client by client_id. The client model class MUST |
| 37 | implement the methods described by |
| 38 | :class:`~authlib.oauth2.rfc6749.ClientMixin`. |
| 39 | """ |
| 40 | raise NotImplementedError() |
| 41 | |
| 42 | def save_token(self, token, request): |
| 43 | """Define function to save the generated token into database.""" |
| 44 | raise NotImplementedError() |
| 45 | |
| 46 | def generate_token( |
| 47 | self, |
| 48 | grant_type, |
| 49 | client, |
| 50 | user=None, |
| 51 | scope=None, |
| 52 | expires_in=None, |
| 53 | include_refresh_token=True, |
| 54 | ): |
| 55 | """Generate the token dict. |
| 56 | |
| 57 | :param grant_type: current requested grant_type. |
| 58 | :param client: the client that making the request. |
| 59 | :param user: current authorized user. |
| 60 | :param expires_in: if provided, use this value as expires_in. |
| 61 | :param scope: current requested scope. |
| 62 | :param include_refresh_token: should refresh_token be included. |
| 63 | :return: Token dict |
| 64 | """ |
| 65 | # generator for a specified grant type |
| 66 | func = self._token_generators.get(grant_type) |
| 67 | if not func: |
| 68 | # default generator for all grant types |
| 69 | func = self._token_generators.get("default") |
| 70 | if not func: |
| 71 | raise RuntimeError("No configured token generator") |
| 72 | |
| 73 | return func( |
| 74 | grant_type=grant_type, |
| 75 | client=client, |
nothing calls this directly
no outgoing calls
no test coverage detected