work in progress: entry points for OpenID Connect (oidc) authentication
This commit is contained in:
parent
b4051147ee
commit
3e25b5e593
5 changed files with 47 additions and 9 deletions
|
@ -1,5 +1,8 @@
|
||||||
# py-scopes/demo/demo_server.py
|
# py-scopes/demo/demo_server.py
|
||||||
|
|
||||||
|
from scopes.server import auth
|
||||||
|
from scopes.storage import topic
|
||||||
|
|
||||||
from wsgiref.simple_server import make_server
|
from wsgiref.simple_server import make_server
|
||||||
|
|
||||||
def run(app, config):
|
def run(app, config):
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
# scopes.interfaces
|
# scopes.interfaces
|
||||||
|
|
||||||
from zope.interface import Interface
|
from zope.interface import Interface, Attribute
|
||||||
|
|
||||||
|
|
||||||
class ITraversable(Interface):
|
class IViewable(Interface):
|
||||||
|
|
||||||
|
prefix = Attribute('Prefix string for identifying the type (class) of an object')
|
||||||
|
|
||||||
|
|
||||||
|
class ITraversable(IViewable):
|
||||||
|
|
||||||
def get(key, default=None):
|
def get(key, default=None):
|
||||||
"""Return the item addressed by `key`; return `default` if not found."""
|
"""Return the item addressed by `key`; return `default` if not found."""
|
||||||
|
|
|
@ -4,6 +4,9 @@ from zope.authentication.interfaces import IAuthentication
|
||||||
from zope.interface import implementer
|
from zope.interface import implementer
|
||||||
from zope.publisher.interfaces import Unauthorized
|
from zope.publisher.interfaces import Unauthorized
|
||||||
|
|
||||||
|
from scopes.server.browser import DefaultView, register
|
||||||
|
from scopes.storage.folder import DummyFolder, Root
|
||||||
|
|
||||||
|
|
||||||
def authenticate(request):
|
def authenticate(request):
|
||||||
#print('*** authenticate')
|
#print('*** authenticate')
|
||||||
|
@ -11,7 +14,7 @@ def authenticate(request):
|
||||||
|
|
||||||
|
|
||||||
@implementer(IAuthentication)
|
@implementer(IAuthentication)
|
||||||
class JwtAuthentication:
|
class OidcAuthentication:
|
||||||
|
|
||||||
def __init__(self, baseAuth):
|
def __init__(self, baseAuth):
|
||||||
self.baseAuth = baseAuth
|
self.baseAuth = baseAuth
|
||||||
|
@ -37,3 +40,19 @@ class JwtAuthentication:
|
||||||
def logout(self, request):
|
def logout(self, request):
|
||||||
print('*** JwtAuthentication: logout')
|
print('*** JwtAuthentication: logout')
|
||||||
|
|
||||||
|
JwtAuthentication = OidcAuthentication # old name - still used?
|
||||||
|
|
||||||
|
|
||||||
|
class Authenticator(DummyFolder):
|
||||||
|
prefix = 'auth'
|
||||||
|
|
||||||
|
|
||||||
|
@register('auth', Root)
|
||||||
|
def authView(context, request):
|
||||||
|
print('*** auth', context, request['PATH_INFO'], request.getTraversalStack())
|
||||||
|
return Authenticator()
|
||||||
|
|
||||||
|
@register('login', Authenticator)
|
||||||
|
def login(context, request):
|
||||||
|
print('*** login', context, request['PATH_INFO'], request.getTraversalStack())
|
||||||
|
return DefaultView(context, request)
|
||||||
|
|
|
@ -12,12 +12,11 @@ def register(name, *contextTypes):
|
||||||
def doRegister(factory):
|
def doRegister(factory):
|
||||||
implementer(IView)(factory)
|
implementer(IView)(factory)
|
||||||
nameEntry = views.setdefault(name, {})
|
nameEntry = views.setdefault(name, {})
|
||||||
for ct in contextTypes:
|
cts = contextTypes or ['']
|
||||||
if not isinstance(ct, string):
|
for ct in cts:
|
||||||
|
if not isinstance(ct, str):
|
||||||
ct = ct.prefix
|
ct = ct.prefix
|
||||||
nameEntry[ct] = factory
|
nameEntry[ct] = factory
|
||||||
else:
|
|
||||||
nameEntry[''] = factory
|
|
||||||
return factory
|
return factory
|
||||||
return doRegister
|
return doRegister
|
||||||
|
|
||||||
|
@ -61,5 +60,3 @@ class DefaultView:
|
||||||
def render(self, result):
|
def render(self, result):
|
||||||
self.request.response.setHeader('Content-type', 'application/json; charset=utf-8')
|
self.request.response.setHeader('Content-type', 'application/json; charset=utf-8')
|
||||||
return json.dumps(result).encode('UTF-8')
|
return json.dumps(result).encode('UTF-8')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,18 @@ from scopes.storage.common import registerContainerClass
|
||||||
from scopes.storage.tracking import Container, Track
|
from scopes.storage.tracking import Container, Track
|
||||||
|
|
||||||
|
|
||||||
|
class DummyFolder(dict):
|
||||||
|
|
||||||
|
prefix = 'dummy'
|
||||||
|
|
||||||
|
def asDict(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return '%s: %s' % (self.__class__.__name__,
|
||||||
|
super(DummyFolder, self).__repr__())
|
||||||
|
|
||||||
|
|
||||||
@implementer(IContainer, IReference)
|
@implementer(IContainer, IReference)
|
||||||
class Folder(Track):
|
class Folder(Track):
|
||||||
|
|
||||||
|
@ -57,6 +69,8 @@ class Root(Folder):
|
||||||
"""A dummy (virtual) root folder for creating real folders
|
"""A dummy (virtual) root folder for creating real folders
|
||||||
using the Folder API."""
|
using the Folder API."""
|
||||||
|
|
||||||
|
prefix = 'root'
|
||||||
|
|
||||||
def __init__(self, storage):
|
def __init__(self, storage):
|
||||||
cont = storage.create(Folders)
|
cont = storage.create(Folders)
|
||||||
super(Root, self).__init__(container=cont)
|
super(Root, self).__init__(container=cont)
|
||||||
|
|
Loading…
Add table
Reference in a new issue