File: rfc7592.rst

package info (click to toggle)
python-authlib 1.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,016 kB
  • sloc: python: 26,998; makefile: 53; sh: 14
file content (99 lines) | stat: -rw-r--r-- 3,746 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
.. _specs/rfc7592:

RFC7592: OAuth 2.0 Dynamic Client Registration Management Protocol
==================================================================

This section contains the generic implementation of RFC7592_. OAuth 2.0 Dynamic
Client Registration Management Protocol allows developers edit and delete OAuth
client via API through Authorization Server. This specification is an extension
of :ref:`specs/rfc7591`.


.. meta::
    :description: Python API references on RFC7592 OAuth 2.0 Dynamic Client
        Registration Management Protocol in Python with Authlib implementation.

.. module:: authlib.oauth2.rfc7592

.. _RFC7592: https://tools.ietf.org/html/rfc7592

Client Configuration Endpoint
-----------------------------

Before register the endpoint, developers MUST implement the missing methods::

    from authlib.oauth2.rfc7592 import ClientConfigurationEndpoint


    class MyClientConfigurationEndpoint(ClientConfigurationEndpoint):
        def authenticate_token(self, request):
            # this method is used to authenticate the registration access
            # token returned by the RFC7591 registration endpoint
            auth_header = request.headers.get('Authorization')
            bearer_token = auth_header.split()[1]
            token = Token.get(bearer_token)
            return token

        def authenticate_client(self, request):
            client_id = request.payload.data.get('client_id')
            return Client.get(client_id=client_id)

        def revoke_access_token(self, token, request):
            token.revoked = True
            token.save()

        def check_permission(self, client, request):
            return client.editable

        def delete_client(self, client, request):
            client.delete()

        def save_client(self, client_info, client_metadata, request):
            client = OAuthClient(
                user_id=request.credential.user_id,
                client_id=client_info['client_id'],
                client_secret=client_info['client_secret'],
                **client_metadata,
            )
            client.save()
            return client

        def generate_client_registration_info(self, client, request):
            access_token = request.headers['Authorization'].split(' ')[1]
            return {
                'registration_client_uri': request.uri,
                'registration_access_token': access_token,
            }

        def get_server_metadata(self):
            return {
                'issuer': ...,
                'authorization_endpoint': ...,
                'token_endpoint': ...,
                'jwks_uri': ...,
                'registration_endpoint': ...,
                'scopes_supported': ...,
                'response_types_supported': ...,
                'response_modes_supported': ...,
                'grant_types_supported': ...,
                'token_endpoint_auth_methods_supported': ...,
                'token_endpoint_auth_signing_alg_values_supported': ...,
                'service_documentation': ...,
                'ui_locales_supported': ...,
                'op_policy_uri': ...,
                'op_tos_uri': ...,
                'revocation_endpoint': ...,
                'revocation_endpoint_auth_methods_supported': ...,
                'revocation_endpoint_auth_signing_alg_values_supported': ...,
                'introspection_endpoint': ...,
                'introspection_endpoint_auth_methods_supported': ...,
                'introspection_endpoint_auth_signing_alg_values_supported': ...,
                'code_challenge_methods_supported': ...,
            }

API Reference
-------------

.. autoclass:: ClientConfigurationEndpoint
    :member-order: bysource
    :members: