File: oauth2_server.py

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 (28 lines) | stat: -rw-r--r-- 806 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
import base64
import os

from authlib.common.encoding import to_bytes
from authlib.common.encoding import to_unicode
from authlib.integrations.django_oauth2 import AuthorizationServer
from tests.django_helper import TestCase as _TestCase

from .models import Client
from .models import OAuth2Token


class TestCase(_TestCase):
    def setUp(self):
        super().setUp()
        os.environ["AUTHLIB_INSECURE_TRANSPORT"] = "true"

    def tearDown(self):
        super().tearDown()
        os.environ.pop("AUTHLIB_INSECURE_TRANSPORT")

    def create_server(self):
        return AuthorizationServer(Client, OAuth2Token)

    def create_basic_auth(self, username, password):
        text = f"{username}:{password}"
        auth = to_unicode(base64.b64encode(to_bytes(text)))
        return "Basic " + auth