work in progress: JWT authentication: baseAuth as property, remove registration function

This commit is contained in:
Helmut Merz 2024-11-16 09:27:01 +01:00
parent a3da3f07f0
commit eaa2055c76
2 changed files with 28 additions and 29 deletions

View file

@ -24,7 +24,6 @@ postgres = [
app = [ app = [
"python-dotenv", "python-dotenv",
"zope.authentication", "zope.authentication",
"zope.component",
"zope.interface", "zope.interface",
"zope.publisher", "zope.publisher",
"zope.traversing", "zope.traversing",

View file

@ -1,38 +1,38 @@
# scopes.server.auth # scopes.server.auth
from zope.authentication.interfaces import IAuthentication from zope.authentication.interfaces import IAuthentication
from zope.principalregistry.principalregistry import PrincipalRegistry
from zope.component import getUtility, provideUtility, queryNextUtility
from zope.interface import implementer from zope.interface import implementer
from zope.publisher.interfaces import Unauthorized
baseAuth = None
class JwtAuthentication(PrincipalRegistry):
def authenticate(self, request):
prc = authenticate(request)
if prc is None:
return baseAuth.authenticate(request)
def getPrincipal(self, id):
return baseAuth.getPrincipal(id)
def unauthenticatedPrincipal(self):
return baseAuth.unauthenticatedPrincipal()
def unauthorized(self, id, request):
return baseAuth.unauthorized(id, request)
def authenticate(request): def authenticate(request):
print('*** authenticate') #print('*** authenticate')
return None return None
def registerAuthUtility(): @implementer(IAuthentication)
global baseAuth class JwtAuthentication:
baseAuth = getUtility(IAuthentication)
print('*** registerAuthUtility, baseAuth:', baseAuth) def __init__(self, baseAuth):
provideUtility(JwtAuthentication(), IAuthentication) self.baseAuth = baseAuth
def authenticate(self, request):
prc = authenticate(request)
if prc is None and self.baseAuth is not None:
prc = self.baseAuth.authenticate(request)
if prc is None:
raise Unauthorized
return prc
def getPrincipal(self, id):
if self.baseAuth is not None:
return self.baseAuth.getPrincipal(id)
def unauthenticatedPrincipal(self):
if self.baseAuth is not None:
return self.baseAuth.unauthenticatedPrincipal()
def unauthorized(self, id, request):
if self.baseAuth is not None:
return self.baseAuth.unauthorized(id, request)