|
1 |
| -from pas.plugins.oidc import utils |
2 | 1 | from pas.plugins.oidc.plugins import OIDCPlugin
|
3 | 2 | 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 |
7 | 7 |
|
8 | 8 |
|
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 |
11 | 14 |
|
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(): |
25 | 19 | if isinstance(plugin, OIDCPlugin):
|
26 |
| - plugins.append( |
| 20 | + options.append( |
27 | 21 | {
|
28 | 22 | "id": plugin.getId(),
|
29 | 23 | "plugin": "oidc",
|
30 |
| - "url": f"{portal_url}/@login-oidc/{plugin.getId()}", |
31 | 24 | "title": plugin.title,
|
| 25 | + "url": f"{self.context.absolute_url()}/@login-oidc/{plugin.getId()}", |
32 | 26 | }
|
33 | 27 | )
|
34 |
| - return plugins |
35 |
| - |
36 |
| - def reply(self) -> Dict[str, List[Dict]]: |
37 |
| - """List login options available for the site. |
38 | 28 |
|
39 |
| - :returns: Login options information. |
40 |
| - """ |
41 |
| - providers = self.list_login_providers() |
42 |
| - return {"options": providers} |
| 29 | + return options |
0 commit comments