provide special view @@auth_select for selection of authentication method

This commit is contained in:
Helmut Merz 2025-10-27 10:59:08 +01:00
parent 5ba5862c9c
commit f4248dcb73
7 changed files with 43 additions and 29 deletions

View file

@ -3,7 +3,7 @@ msgstr ""
"Project-Id-Version: 3.0.1\n"
"POT-Creation-Date: 2007-05-22 12:00 CET\n"
"PO-Revision-Date: 2025-10-26 12:00 CET\n"
"PO-Revision-Date: 2025-10-27 12:00 CET\n"
"Last-Translator: Helmut Merz <helmutm@cy55.de>\n"
"Language-Team: loops developers <helmutm@cy55.de>\n"
"MIME-Version: 1.0\n"
@ -1478,6 +1478,9 @@ msgstr "Mit OpenID Connect (Zitadel) anmelden"
msgid "edit-external-user"
msgstr "Login-Einstellungen bearbeiten"
msgid "set-authentication-method"
msgstr "Login-Verfahren einstellen"
msgid "authentication-method"
msgstr "Login-Verfahren"

View file

@ -61,13 +61,6 @@ class PersonalInfo(ConceptView):
def view(self):
return self
@Lazy
def selectAuthMethod(self):
return getattr(config, 'authentication_method', 'legacy') == 'cookie'
def getAuthMethod(self):
return self.request.cookies.get('loops_auth_method') or 'legacy'
@Lazy
def extUserLink(self):
from scopes.web.auth.oidc import IExternalPrincipal

View file

@ -60,20 +60,6 @@
<li tal:condition="python:item.globalOptions('organize.useFilters')">
<a href="edit_filters.html"
i18n:translate="">Edit Filters</a></li>
<li tal:condition="item/selectAuthMethod">
<span i18n:translate="authentication-method">Authentication Method</span>:
<select name="auth_method"
onchange="document.cookie=`loops_auth_method=${this.value}; path=/`"
tal:define="meth item/getAuthMethod"
tal:attributes="value meth">
<option value="legacy" i18n:translate="authentication-method-legacy"
tal:attributes="selected python:meth=='legacy'">Legacy</option>
<option value="oidc" i18n:translate="authentication-method-oidc"
tal:attributes="selected python:meth=='oidc'">OIDC</option>
<option value="select" i18n:translate="authentication-method-select"
tal:attributes="selected python:meth=='select'">Selection</option>
</select>
</li>
</ul>
</metal:block>
</metal:block>

View file

@ -23,19 +23,18 @@ def registerAuthUtility(config):
class LoginPage:
index = ViewPageTemplateFile('loginform.pt')
showSelection = False
def __init__(self, context, request):
self.context = context
self.request = request
self.authMethod = getattr(config, 'authentication_method', 'legacy')
self.authMethod = getConfigAuthMethod()
if self.authMethod == 'cookie':
self.authMethod = getAuthMethodCookieValue(request)
self.oidc_allowed = self.authMethod in ('oidc', 'select')
self.oidc_allowed = self.showSelection or self.authMethod in ('oidc', 'select')
def __call__(self):
print('***', self.request.principal.id)
print('***', self.authMethod)
if self.authMethod == 'oidc':
if self.authMethod == 'oidc' and not self.showSelection:
return self.authOidc()
return self.index()
@ -43,8 +42,18 @@ class LoginPage:
oidc.Authenticator(self.request).login()
return ''
class LoginPageSelect(LoginPage):
@property
def showSelection(self):
return getConfigAuthMethod() == 'cookie'
def getConfigAuthMethod():
return getattr(config, 'authentication_method', 'legacy')
def getAuthMethodCookieValue(request):
print('***', dict(request.cookies))
return request.cookies.get('loops_auth_method') or 'legacy'

View file

@ -20,6 +20,7 @@
<div metal:fill-slot="body"
tal:define="principal python:request.principal.id;
camefrom python:request.get('camefrom') or request.URL[-1]">
<p i18n:translate="" tal:condition="python: principal == 'zope.anybody'">
Please provide Login Information</p>
<p i18n:translate="" tal:condition="python: principal != 'zope.anybody'">
@ -43,7 +44,6 @@
<input type="text" name="login"/>
</div>
</div>
<div class="row">
<div class="label" i18n:translate="">Password</div>
<div class="field">
@ -58,6 +58,23 @@
<input type="hidden" name="camefrom"
tal:attributes="value request/camefrom | nothing">
</form>
<div tal:condition="view/showSelection"
i18n:domain="loops">
<br>
<p><b i18n:translate="set-authentication-method">Set Authentication Method</b></p>
<span i18n:translate="authentication-method">Authentication Method</span>:
<select name="auth_method"
onchange="document.cookie=`loops_auth_method=${this.value}; path=/`"
tal:define="meth view/authMethod"
tal:attributes="value meth">
<option value="legacy" i18n:translate="authentication-method-legacy"
tal:attributes="selected python:meth=='legacy'">Legacy</option>
<option value="oidc" i18n:translate="authentication-method-oidc"
tal:attributes="selected python:meth=='oidc'">OIDC</option>
<option value="select" i18n:translate="authentication-method-select"
tal:attributes="selected python:meth=='select'">Selection</option>
</select>
</div>
</div>
</body>

View file

@ -8,5 +8,11 @@
permission="zope.Public"
layer="cybertools.browser.loops.Loops" />
<browser:page for="*"
name="auth_select"
class="loops.server.auth.LoginPageSelect"
permission="zope.Public"
layer="cybertools.browser.loops.Loops" />
</configure>