File: rfc7009.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 (60 lines) | stat: -rw-r--r-- 1,874 bytes parent folder | download | duplicates (4)
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
.. _specs/rfc7009:

RFC7009: OAuth 2.0 Token Revocation
===================================

.. meta::
    :description: API references on RFC7009 OAuth 2.0 Token Revocation Authlib implementation.

This section contains the generic implementation of RFC7009_.

.. _RFC7009: https://tools.ietf.org/html/rfc7009

.. module:: authlib.oauth2.rfc7009

.. _register_revocation_endpoint:

Register Revocation Endpoint
----------------------------

The revocation endpoint can be easily registered to :ref:`flask_oauth2_server`
or :ref:`django_oauth2_server`. But there are missing methods to be
implemented::

    from authlib.oauth2.rfc7009 import RevocationEndpoint

    class MyRevocationEndpoint(RevocationEndpoint):
        def query_token(self, token, token_type_hint, client):
            q = Token.query.filter_by(client_id=client.client_id)
            if token_type_hint == 'access_token':
                return q.filter_by(access_token=token).first()
            elif token_type_hint == 'refresh_token':
                return q.filter_by(refresh_token=token).first()
            # without token_type_hint
            item = q.filter_by(access_token=token).first()
            if item:
                return item
            return q.filter_by(refresh_token=token).first()

        def revoke_token(self, token):
            token.revoked = True
            db.session.add(token)
            db.session.commit()

    # register it to authorization server
    authorization_server.register_endpoint(MyRevocationEndpoint)

After the registration, you can create a response with::

    @app.route('/oauth/revoke', methods=['POST'])
    def revoke_token():
        return server.create_endpoint_response(MyRevocationEndpoint.ENDPOINT_NAME)


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

.. autoclass:: RevocationEndpoint
    :member-order: bysource
    :members:
    :inherited-members: