Beispiel #1
0
def test_not_authenticated():
    a = Identity({
        'oid': 'bc5f60df-4c27-49c1-8466-acf32618a6d2'
    })

    assert a.authentication_mode is None
    assert a.is_authenticated() is False
Beispiel #2
0
def test_authenticated():
    a = Identity({
        'oid': 'bc5f60df-4c27-49c1-8466-acf32618a6d2'
    }, 'JWT Bearer')

    assert a.authentication_mode == 'JWT Bearer'
    assert a.is_authenticated()
Beispiel #3
0
    def authorize(self, policy_name: Optional[str], identity: Identity):
        if policy_name:
            policy = self.get_policy(policy_name)

            if not policy:
                raise PolicyNotFoundError(policy_name)

            self._handle_with_policy(policy, identity)
        else:
            if self.default_policy:
                self._handle_with_policy(self.default_policy, identity)
                return

            if not identity:
                raise UnauthorizedError('Missing identity', [])
            if not identity.is_authenticated():
                raise UnauthorizedError('The resource requires authentication',
                                        [])