misc: add next_url parameter to Authenticator.autorun() (#27135)
This commit is contained in:
parent
9e7e6dcfba
commit
f34b2af379
|
@ -415,7 +415,7 @@ def login(request, template_name='authentic2/login.html', redirect_field_name=RE
|
|||
if hasattr(authenticator, 'autorun'):
|
||||
if 'message' in token:
|
||||
messages.info(request, token['message'])
|
||||
return authenticator.autorun(request, block.get('id'))
|
||||
return authenticator.autorun(request, block_id=block.get('id'), next_url=redirect_to)
|
||||
|
||||
context.update(
|
||||
{
|
||||
|
|
|
@ -118,8 +118,8 @@ class FcAuthenticator(BaseAuthenticator):
|
|||
else:
|
||||
return 'https://app.franceconnect.gouv.fr/api/v1/logout'
|
||||
|
||||
def autorun(self, request, block_id):
|
||||
return views.LoginOrLinkView.as_view(display_message_on_redirect=True)(request)
|
||||
def autorun(self, request, block_id, next_url):
|
||||
return views.LoginOrLinkView.as_view(display_message_on_redirect=True)(request, next_url=next_url)
|
||||
|
||||
def login(self, request, *args, **kwargs):
|
||||
return views.login(request, *args, **kwargs)
|
||||
|
|
|
@ -147,7 +147,10 @@ class LoginOrLinkView(View):
|
|||
display_name += family_name
|
||||
return display_name
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
def get(self, request, *args, next_url=None, **kwargs):
|
||||
if next_url:
|
||||
self._next_url = next_url
|
||||
|
||||
self.authenticator = get_object_or_404(models.FcAuthenticator, enabled=True)
|
||||
|
||||
code = request.GET.get('code')
|
||||
|
|
|
@ -232,8 +232,10 @@ class OIDCProvider(BaseAuthenticator):
|
|||
def __repr__(self):
|
||||
return '<OIDCProvider %r>' % self.issuer
|
||||
|
||||
def autorun(self, request, *args):
|
||||
return redirect_to_login(request, login_url='oidc-login', kwargs={'pk': self.pk})
|
||||
def autorun(self, request, block_id, next_url):
|
||||
return redirect_to_login(
|
||||
request, login_url='oidc-login', kwargs={'pk': self.pk}, params={'next': next_url}
|
||||
)
|
||||
|
||||
def login(self, request, *args, **kwargs):
|
||||
context = kwargs.get('context', {}).copy()
|
||||
|
|
|
@ -230,13 +230,13 @@ class SAMLAuthenticator(BaseAuthenticator):
|
|||
if not (self.metadata or self.metadata_url):
|
||||
raise ValidationError(_('One of the metadata fields must be filled.'))
|
||||
|
||||
def autorun(self, request, block_id):
|
||||
def autorun(self, request, block_id, next_url):
|
||||
from .adapters import AuthenticAdapter
|
||||
|
||||
settings = self.settings
|
||||
AuthenticAdapter().load_idp(settings, self.order)
|
||||
return redirect_to_login(
|
||||
request, login_url='mellon_login', params={'entityID': settings['ENTITY_ID']}
|
||||
request, login_url='mellon_login', params={'entityID': settings['ENTITY_ID'], 'next': next_url}
|
||||
)
|
||||
|
||||
def has_signing_key(self):
|
||||
|
|
|
@ -492,7 +492,7 @@ def test_login_autorun(oidc_provider, app, settings):
|
|||
slug='password-authenticator', defaults={'enabled': False}
|
||||
)
|
||||
response = app.get('/login/', status=302)
|
||||
assert response['Location'] == '/accounts/oidc/login/%s/' % oidc_provider.pk
|
||||
assert response['Location'] == '/accounts/oidc/login/%s/?next=/' % oidc_provider.pk
|
||||
|
||||
|
||||
def test_sso(app, caplog, code, oidc_provider, oidc_provider_jwkset, hooks):
|
||||
|
|
Loading…
Reference in New Issue