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
|
||||
|
||||
from scopes.server import auth
|
||||
from scopes.storage import topic
|
||||
|
||||
from wsgiref.simple_server import make_server
|
||||
|
||||
def run(app, config):
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
# 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):
|
||||
"""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.publisher.interfaces import Unauthorized
|
||||
|
||||
from scopes.server.browser import DefaultView, register
|
||||
from scopes.storage.folder import DummyFolder, Root
|
||||
|
||||
|
||||
def authenticate(request):
|
||||
#print('*** authenticate')
|
||||
|
@ -11,7 +14,7 @@ def authenticate(request):
|
|||
|
||||
|
||||
@implementer(IAuthentication)
|
||||
class JwtAuthentication:
|
||||
class OidcAuthentication:
|
||||
|
||||
def __init__(self, baseAuth):
|
||||
self.baseAuth = baseAuth
|
||||
|
@ -37,3 +40,19 @@ class JwtAuthentication:
|
|||
def logout(self, request):
|
||||
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):
|
||||
implementer(IView)(factory)
|
||||
nameEntry = views.setdefault(name, {})
|
||||
for ct in contextTypes:
|
||||
if not isinstance(ct, string):
|
||||
cts = contextTypes or ['']
|
||||
for ct in cts:
|
||||
if not isinstance(ct, str):
|
||||
ct = ct.prefix
|
||||
nameEntry[ct] = factory
|
||||
else:
|
||||
nameEntry[''] = factory
|
||||
return factory
|
||||
return doRegister
|
||||
|
||||
|
@ -61,5 +60,3 @@ class DefaultView:
|
|||
def render(self, result):
|
||||
self.request.response.setHeader('Content-type', 'application/json; charset=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
|
||||
|
||||
|
||||
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)
|
||||
class Folder(Track):
|
||||
|
||||
|
@ -57,6 +69,8 @@ class Root(Folder):
|
|||
"""A dummy (virtual) root folder for creating real folders
|
||||
using the Folder API."""
|
||||
|
||||
prefix = 'root'
|
||||
|
||||
def __init__(self, storage):
|
||||
cont = storage.create(Folders)
|
||||
super(Root, self).__init__(container=cont)
|
||||
|
|
Loading…
Add table
Reference in a new issue