コード例 #1
0
 def validate(self, attrs):
     request = self.context.get("request")
     client_ip, is_routable = get_client_ip(request)
     is_valid, instance = ScopedAPIKey.objects.is_valid_with_logging(
         api_key=attrs['api_key'], extra={'ip': client_ip})
     if not is_valid or not instance:
         raise AuthenticationFailed('Api key has expired or is invalid')
     jwt_backend_class = JWTBackendRegistry.get_instance().get_backend(
         instance.jwt_backend_name)
     if not jwt_backend_class:
         raise AuthenticationFailed(
             'Unknown jwt backend could not authenticate')
     backend = jwt_backend_class()
     return backend.make_authenticate_success_response(
         base_payload={
             **instance.base_jwt_payload, 'api_key_id': instance.id
         })
コード例 #2
0
 def ready(self):
     from ievv_auth.ievv_jwt.backends.backend_registry import JWTBackendRegistry
     from ievv_auth.ievv_jwt.backends.api_key_backend import ApiKeyBackend
     registry = JWTBackendRegistry.get_instance()
     registry.set_backend(ApiKeyBackend)
コード例 #3
0
 def test_unknown_backend(self):
     registry = JWTBackendRegistry.get_instance()
     backend_class = registry.get_backend('unknown')
     self.assertIsNone(backend_class)
コード例 #4
0
 def test_sanity(self):
     registry = JWTBackendRegistry.get_instance()
     backend_class = registry.get_backend('api-key')
     self.assertEqual(backend_class, ApiKeyBackend)
コード例 #5
0
 def setUp(self):
     registry = JWTBackendRegistry.get_instance()
     registry.set_backend(ApiKeyBackend)
コード例 #6
0
 def __init__(self, *args, **kwargs):
     super(ScopedAPIKeyForm, self).__init__(*args, **kwargs)
     self.fields[
         'jwt_backend_name'].choices = JWTBackendRegistry.get_instance(
         ).get_backend_choices()