Skip to content

Commit d950039

Browse files
authored
register the adapter instead of the @login endpoint (#47)
* register the adapter instead of the @login endpoint * changelog
1 parent 03a8c3b commit d950039

File tree

3 files changed

+20
-36
lines changed

3 files changed

+20
-36
lines changed

Diff for: news/47.feature

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Register the adapter as needed by the @login endpoint present in plone.restapi @erral

Diff for: src/pas/plugins/oidc/services/login/configure.zcml

+3-7
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,8 @@
44
>
55

66
<!-- Login options -->
7-
<plone:service
8-
method="GET"
9-
factory=".get.Get"
10-
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
11-
permission="zope.Public"
12-
name="@login"
7+
<adapter
8+
factory=".get.OIDCLoginProviders"
9+
name="pas-plugins-oidc-providers"
1310
/>
14-
1511
</configure>

Diff for: src/pas/plugins/oidc/services/login/get.py

+16-29
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,29 @@
1-
from pas.plugins.oidc import utils
21
from pas.plugins.oidc.plugins import OIDCPlugin
32
from plone import api
4-
from plone.restapi.services import Service
5-
from typing import Dict
6-
from typing import List
3+
from plone.base.interfaces import IPloneSiteRoot
4+
from plone.restapi.interfaces import ILoginProviders
5+
from zope.component import adapter
6+
from zope.interface import implementer
77

88

9-
class Get(Service):
10-
"""List available login options for the site."""
9+
@adapter(IPloneSiteRoot)
10+
@implementer(ILoginProviders)
11+
class OIDCLoginProviders:
12+
def __init__(self, context):
13+
self.context = context
1114

12-
def check_permission(self):
13-
return True
14-
15-
@staticmethod
16-
def list_login_providers() -> List[Dict]:
17-
"""List all configured login providers.
18-
19-
This should be moved to plone.restapi and be extendable.
20-
:returns: List of login options.
21-
"""
22-
portal_url = api.portal.get().absolute_url()
23-
plugins = []
24-
for plugin in utils.get_plugins():
15+
def get_providers(self):
16+
options = []
17+
acl_users = api.portal.get_tool("acl_users")
18+
for plugin in acl_users.objectValues():
2519
if isinstance(plugin, OIDCPlugin):
26-
plugins.append(
20+
options.append(
2721
{
2822
"id": plugin.getId(),
2923
"plugin": "oidc",
30-
"url": f"{portal_url}/@login-oidc/{plugin.getId()}",
3124
"title": plugin.title,
25+
"url": f"{self.context.absolute_url()}/@login-oidc/{plugin.getId()}",
3226
}
3327
)
34-
return plugins
35-
36-
def reply(self) -> Dict[str, List[Dict]]:
37-
"""List login options available for the site.
3828

39-
:returns: Login options information.
40-
"""
41-
providers = self.list_login_providers()
42-
return {"options": providers}
29+
return options

0 commit comments

Comments
 (0)