Skip to content

ui_locales request parameter triggers AttributeError under certain circumstances #1468

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

Closed
2 tasks done
jaap3 opened this issue Aug 26, 2024 · 2 comments · Fixed by #1469
Closed
2 tasks done

ui_locales request parameter triggers AttributeError under certain circumstances #1468

jaap3 opened this issue Aug 26, 2024 · 2 comments · Fixed by #1469
Labels

Comments

@jaap3
Copy link

jaap3 commented Aug 26, 2024

Describe the bug

A valid authorization request, for a client that doesn't require consent, that includes the ui_locales parameter triggers AttributeError: 'list' object has no attribute 'split'.

To Reproduce

  • Configure DOT, with OIDC enabled.
  • Create an Application and set skip_authorization
  • While logged in trigger an authorization request that includes the scope and ui_locales parameter, i.e.:
    /o/authorize/?response_type=code&client_id=test&scope=openid&ui_locales=de

Expected behavior

I expect the authorization request to succeed and the user to be redirected to the redirect_uri with a code response.

Version

django==5.1
django-oauth-toolkit==2.4.0
oauthlib==3.2.2

  • I have tested with the latest published release and it's still a problem.
  • I have tested with the master branch and it's still a problem.

Additional context

I've written a testcase that triggers the issue, TestUILocalesParam.test_trusted_application_ui_locales_param is the one that fails:

from django.contrib.auth import get_user_model
from django.test import TestCase, override_settings
from django.urls import reverse

from oauth2_provider.models import get_application_model

UserModel = get_user_model()
Application = get_application_model()


@override_settings(OAUTH2_PROVIDER={
    "OIDC_ENABLED": True,
    "PKCE_REQUIRED": False,
    "SCOPES": {
        "openid": "OpenID connect",
    },
})
class TestUILocalesParam(TestCase):
    @classmethod
    def setUpTestData(cls):
        cls.application = Application.objects.create(
            name="Test Application",
            client_id="test",
            redirect_uris="https://www.example.com",
            client_type=Application.CLIENT_PUBLIC,
            authorization_grant_type=Application.GRANT_AUTHORIZATION_CODE,
        )
        cls.trusted_application = Application.objects.create(
            name="Trusted Application",
            client_id="trusted",
            redirect_uris="https://www.example.com",
            client_type=Application.CLIENT_PUBLIC,
            authorization_grant_type=Application.GRANT_AUTHORIZATION_CODE,
            skip_authorization=True,
        )
        cls.user = UserModel.objects.create_user("test_user")
        cls.url = reverse("oauth2_provider:authorize")

    def setUp(self):
        self.client.force_login(self.user)

    def test_application_ui_locales_param(self):
        response = self.client.get(
            f"{self.url}?response_type=code&client_id=test&scope=openid&ui_locales=de",
        )
        self.assertEqual(response.status_code, 200)

    def test_trusted_application_ui_locales_param(self):
        response = self.client.get(
            f"{self.url}?response_type=code&client_id=trusted&scope=openid&ui_locales=de",
        )
        self.assertEqual(response.status_code, 302)

My guess is that the call to self.create_authorization_response in

if application.skip_authorization:
uri, headers, body, status = self.create_authorization_response(
request=self.request, scopes=" ".join(scopes), credentials=credentials, allow=True
)
return self.redirect(uri, application)
triggers this issue because it tries to parse the request parameters for the second time, the first time is here:
scopes, credentials = self.validate_authorization_request(request)

@n2ygk
Copy link
Member

n2ygk commented Aug 26, 2024

@n2ygk
Copy link
Member

n2ygk commented Aug 26, 2024

@jaap3 A PR to fix this would be greatly appreciated

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

Successfully merging a pull request may close this issue.

3 participants
@jaap3 @n2ygk and others