-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
register the adapter instead of the @login endpoint
- Loading branch information
Showing
2 changed files
with
19 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |