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

Allow custom query params to be specified in the URL rather than in the settings #537

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion mozilla_django_oidc/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,11 @@ def get(self, request):
return HttpResponseRedirect(redirect_url)

def get_extra_params(self, request):
return self.get_settings("OIDC_AUTH_REQUEST_EXTRA_PARAMS", {})
extra_params = {}
for allowed_param_name in self.get_settings('OIDC_AUTH_REQUEST_EXTRA_PARAMS', []):
if allowed_param_name in request.GET:
extra_params[allowed_param_name] = request.GET[allowed_param_name]
return extra_params


class OIDCLogoutView(View):
Expand Down
6 changes: 2 additions & 4 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,14 +632,12 @@ def test_get_namespaced(self, mock_views_random):
@override_settings(OIDC_OP_AUTHORIZATION_ENDPOINT="https://server.example.com/auth")
@override_settings(OIDC_RP_CLIENT_ID="example_id")
@override_settings(OIDC_USE_PKCE=True)
@override_settings(
OIDC_AUTH_REQUEST_EXTRA_PARAMS={"audience": "some-api.example.com"}
)
@override_settings(OIDC_AUTH_REQUEST_EXTRA_PARAMS=['audience'])
@patch("mozilla_django_oidc.views.get_random_string")
def test_get_with_audience(self, mock_views_random):
"""Test initiation of a successful OIDC attempt."""
mock_views_random.return_value = "examplestring"
url = reverse("oidc_authentication_init")
url = reverse('oidc_authentication_init') + "?audience=some-api.example.com"
request = self.factory.get(url)
request.session = dict()
login_view = views.OIDCAuthenticationRequestView.as_view()
Expand Down