Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

register the adapter instead of the @login endpoint #73

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
51 changes: 20 additions & 31 deletions src/pas/plugins/authomatic/services/login.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,29 @@
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(
dict(
id=provider_id,
plugin="authomatic",
title=title,
)
options.append(
{
"id": provider_id,
"plugin": "authomatic",
"title": title,
"url": f"{self.context.absolute_url()}/@login-authomatic/${provider_id}",
}
)
return plugins

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

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