def test_custom_authorization_header(self):
        headers = {
            'HTTP_AUTHORIZATION_TOKEN': 'JWT token',
        }

        request = self.factory.get('/', **headers)
        header = utils.get_authorization_header(request)

        self.assertEqual(header, 'token')
    def test_custom_authorization_header(self):
        headers = {
            'HTTP_AUTHORIZATION_TOKEN': 'JWT token',
        }

        request = self.factory.get('/', **headers)
        header = utils.get_authorization_header(request)

        self.assertEqual(header, 'token')
    def test_invalid_authorization_header_prefix(self):
        headers = {
            'HTTP_AUTHORIZATION': 'INVALID token',
        }

        request = self.factory.get('/', **headers)
        header = utils.get_authorization_header(request)

        self.assertIsNone(header)
    def test_invalid_authorization_header_prefix(self):
        headers = {
            'HTTP_AUTHORIZATION': 'INVALID token',
        }

        request = self.factory.get('/', **headers)
        header = utils.get_authorization_header(request)

        self.assertIsNone(header)
Beispiel #5
0
    def test_invalid_header_prefix(self):
        headers = {
            jwt_settings.JWT_AUTH_HEADER_NAME: 'INVALID token',
        }

        request = self.request_factory.get('/', **headers)
        authorization_header = utils.get_authorization_header(request)

        self.assertIsNone(authorization_header)
Beispiel #6
0
    def test_get_header(self):
        headers = {
            jwt_settings.JWT_AUTH_HEADER_NAME:
            '{} {}'.format(jwt_settings.JWT_AUTH_HEADER_PREFIX, self.token),
        }

        request = self.request_factory.get('/', **headers)
        authorization_header = utils.get_authorization_header(request)

        self.assertEqual(authorization_header, self.token)
Beispiel #7
0
    def test_custom_authorization_header(self):
        headers = {
            'HTTP_AUTHORIZATION_TOKEN': '{} token'.format(
                jwt_settings.JWT_AUTH_HEADER_PREFIX),
        }

        request = self.factory.get('/', **headers)
        header = utils.get_authorization_header(request)

        self.assertEqual(header, 'token')
Beispiel #8
0
    def authenticate(self, request= None, **credentials):
        if request is None:
            return None

        token = get_authorization_header(request)

        if token is not None:
            return User.find_by_token(token)

        return None