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 #47

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
12 changes: 4 additions & 8 deletions src/pas/plugins/oidc/services/login/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@
>

<!-- Login options -->
<plone:service
method="GET"
factory=".get.Get"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
permission="zope.Public"
name="@login"
/>

<adapter
factory=".get.OIDCLoginProviders"
name="pas-plugins-oidc-providers"
/>
</configure>
45 changes: 16 additions & 29 deletions src/pas/plugins/oidc/services/login/get.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,29 @@
from pas.plugins.oidc import utils
from pas.plugins.oidc.plugins import OIDCPlugin
from plone import api
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 ILoginProviders
from zope.component import adapter
from zope.interface import implementer


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

def check_permission(self):
return True

@staticmethod
def list_login_providers() -> List[Dict]:
"""List all configured login providers.

This should be moved to plone.restapi and be extendable.
:returns: List of login options.
"""
portal_url = api.portal.get().absolute_url()
plugins = []
for plugin in utils.get_plugins():
def get_providers(self):
options = []
acl_users = api.portal.get_tool("acl_users")
for plugin in acl_users.objectValues():
if isinstance(plugin, OIDCPlugin):
plugins.append(
options.append(
{
"id": plugin.getId(),
"plugin": "oidc",
"url": f"{portal_url}/@login-oidc/{plugin.getId()}",
"title": plugin.title,
"url": f"{self.context.absolute_url()}/@login-oidc/{plugin.getId()}",
}
)
return plugins

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

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