Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for prompt=create #1470

Open
jaap3 opened this issue Aug 28, 2024 · 1 comment
Open

Support for prompt=create #1470

jaap3 opened this issue Aug 28, 2024 · 1 comment

Comments

@jaap3
Copy link
Contributor

jaap3 commented Aug 28, 2024

The Initiating User Registration via OpenID Connect 1.0 specification defines that the prompt=create can be used to explicitly signal that user desires to create a new account rather than authenticate using an existing identity.

I was able to hack in support for this parameter in DOT by overriding the AuthorizationView and adding some overrides here and there:

from oauth2_provider import views as oauth2_views

from django.contrib.auth.models import AnonymousUser


def _has_prompt_create(request):
    # Check if the prompt=create parameter is present in the request.
    # This parameter is used to explicitly signal that user desires to
    # create a new account rather than authenticate using an existing identity.
    # https://openid.net/specs/openid-connect-prompt-create-1_0.html
    return request.GET.get("prompt") == "create"


class AuthorizationView(oauth2_views.AuthorizationView):
    registration_url = "accounts:register"

    def get(self, request, *args, **kwargs):
        if _has_prompt_create(request):
            # Switch request.user to AnonymousUser. This forces handle_no_permission
            # to issue a redirect instead of raising a PermissionDenied exception if
            # a user is currently logged-in.
            self.request.user = AnonymousUser()
            return self.handle_no_permission()
        return super().get(request, *args, **kwargs)

    def get_login_url(self):
        if _has_prompt_create(self.request):
            # The current URL is used as the redirect URL after registration.
            # Drop the prompt=create parameter to return to the authorization flow,
            # without ending up in a redirect loop.
            query = self.request.GET.copy()
            query.pop("prompt")
            self.request.META["QUERY_STRING"] = query.urlencode()
            return self.registration_url
        return super().get_login_url()

This might not be the ideal solution, but it's the best I could think of given how this view is implemented.

I'm opening this as a feature request, fully understanding that this is not a feature every user of DOT requires. I would've started a discussion instead, but this repository doesn't have github discussions enabled.

@n2ygk
Copy link
Member

n2ygk commented Aug 28, 2024

@jaap3 jazzband/help#371

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants