File: resource-server.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 (20 lines) | stat: -rw-r--r-- 783 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
Protect Resources
=================

Protect users resources, so that only the authorized clients with the
authorized access token can access the given scope resources.

A resource server can be a different server other than the authorization
server. Here is the way to protect your users' resources::

    from django.http import JsonResponse
    from authlib.integrations.django_oauth1 import ResourceProtector
    require_oauth = ResourceProtector(Client, TokenCredential)

    @require_oauth()
    def user_api(request):
        user = request.oauth1_credential.user
        return JsonResponse(dict(username=user.username))

The ``require_oauth`` decorator will add a ``oauth1_credential`` to ``request``
parameter. This ``oauth1_credential`` is an instance of the Token model.