diff --git a/loops/server/auth.py b/loops/server/auth.py index 1240255..37a33b8 100644 --- a/loops/server/auth.py +++ b/loops/server/auth.py @@ -5,10 +5,49 @@ from scopes.server import auth from zope.authentication.interfaces import IAuthentication -from zope.component import getUtility, provideUtility +from zope.component import provideAdapter, getUtility, provideUtility +from zope.interface import implementer, Interface +from zope.publisher.interfaces.browser import IBrowserRequest, IBrowserPage +from zope.publisher.browser import BrowserPage +from zope.security.proxy import removeSecurityProxy + +def registerAuthentication(config): + registerAuthUtility(config) + #registerAuthViews(config) def registerAuthUtility(config): baseAuth = getUtility(IAuthentication) print('*** registerAuthUtility, baseAuth:', baseAuth) - provideUtility(auth.JwtAuthentication(baseAuth)) - + provideUtility(auth.OidcAuthentication(baseAuth)) + +def registerAuthViews(config): + provideAdapter(LoginView, (Interface, IBrowserRequest), IBrowserPage, + name='auth_login') + provideAdapter(callback, (Interface, IBrowserRequest), IBrowserPage, + name='auth_callback') + +@implementer(IBrowserPage) +def login(context, request): + removeSecurityProxy(context) + auth.Authenticator(request).login() + return context + +@implementer(IBrowserPage) +def callback(context, request): + removeSecurityProxy(context) + auth.Authenticator(request).callback() + return DummyView(context, request) + + +class LoginView: + + def __call__(self): + auth.Authenticator(self.request).login() + return '' + + +class CallbackView: + + def __call__(self): + auth.Authenticator(self.request).callback() + return '' diff --git a/loops/server/main.py b/loops/server/main.py index 96a53f5..969f409 100644 --- a/loops/server/main.py +++ b/loops/server/main.py @@ -23,7 +23,8 @@ def main(): zope_conf = getattr(config, 'zope_conf', 'zope.conf') print(f'starting loops server... - conf: {zope_conf}') app = getWSGIApplication(zope_conf) - auth.registerAuthUtility(config) + #auth.registerAuthUtility(config) + auth.registerAuthentication(config) run(app, config) if __name__ == '__main__':