Skip to content

Commit

Permalink
register the adapter instead of the @login endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
erral committed Mar 3, 2024
1 parent d35f00e commit 9b206ed
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 32 deletions.
11 changes: 4 additions & 7 deletions src/pas/plugins/authomatic/services/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@

<include package="plone.restapi" />
<!-- List authentication options -->
<plone:service
method="GET"
factory=".login.Get"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
permission="zope.Public"
name="@login"
/>
<adapter
factory=".login.AuthomaticLoginProviders"
name="pas-plugins-authomatic-providers"
/>

<!-- Authomatic authentication services -->
<plone:service
Expand Down
40 changes: 15 additions & 25 deletions src/pas/plugins/authomatic/services/login.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,30 @@
from pas.plugins.authomatic.utils import authomatic_cfg
from plone.restapi.services import Service
from typing import Dict
from typing import List
from plone.base.interfaces import IPloneSiteRoot
from plone.restapi.interfaces import IExternalLoginProviders
from zope.component import adapter
from zope.interface import implementer


class Get(Service):
"""List available login options for the site."""
@adapter(IPloneSiteRoot)
@implementer(IExternalLoginProviders)
class AuthomaticLoginProviders:
def __init__(self, context):
self.context = context

@staticmethod
def list_plugins() -> List[Dict]:
"""List all configured Authomatic plugins.
:returns: List of login options.
"""
try:
providers = authomatic_cfg()
except KeyError:
# Authomatic is not configured
providers = {}
plugins = []
def get_providers(self):
options = []
providers = authomatic_cfg()
for provider_id, provider in providers.items():
entry = provider.get("display", {})
title = entry.get("title", provider_id)
plugins.append(
options.append(
dict(
id=provider_id,
plugin="authomatic",
title=title,
url=self.context.absolute_url() + '/@login-authomatic/' + provider_id
)
)
return plugins

def reply(self) -> Dict[str, List[Dict]]:
"""List login options available for the site.
return {"options": options}

:returns: Login options information.
"""
providers = self.list_plugins()
return {"options": providers}

0 comments on commit 9b206ed

Please sign in to comment.