Skip to content

Commit ef68972

Browse files
authored
AAP-45580 Add callback url to generic OIDC authenticator (#771)
## Description <!-- Mandatory: Provide a clear, concise description of the changes and their purpose --> - What is being changed? Adding CALLBACK_URL to generic OIDC authenticator plug-in. - Why is this change needed? To provide the callback url via the UI. - How does this change address the issue? The UI automatically presents the callback URL when present. ## Type of Change <!-- Mandatory: Check one or more boxes that apply --> - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Documentation update - [x] Test update - [ ] Refactoring (no functional changes) - [ ] Development environment change - [ ] Configuration change ## Self-Review Checklist <!-- These items help ensure quality - they complement our automated CI checks --> - [x] I have performed a self-review of my code - [x] I have added relevant comments to complex code sections - [ ] I have updated documentation where needed - [x] I have considered the security impact of these changes - [x] I have considered performance implications - [x] I have thought about error handling and edge cases - [x] I have tested the changes in my local environment ### Required Actions <!-- Check if changes require work in other areas --> <!-- Remove section if no external actions needed --> - [x] Requires documentation updates <!-- API docs, feature docs, deployment guides --> The Configuring authentication in the Ansible Automation Platform section on configuring generic OIDC authentication requires updating similarly to that of configuring SAML authentication. The update needed is the inclusion of a suitably worded version of the following from SAML.... > The SAML Assertion Consumer Service (ACS) URL field registers the service as a service provider (SP) with each identity provider (IdP) you have configured. Leave this field blank. After you save this authentication method, it is auto generated. This field must match the Reply URL setting in your IdP. Something like the following... > The OIDC Callback URL field registers the service as a service provider (SP) with each OIDC provider (IdP) you have configured. Leave this field blank. After you save this authentication method, it is auto generated. This field must match the Redirect Endpoint URL setting in your IdP.
1 parent c20ce6e commit ef68972

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

ansible_base/authentication/authenticator_plugins/oidc.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from social_core.backends.open_id_connect import OpenIdConnectAuth
1010

1111
from ansible_base.authentication.authenticator_plugins.base import AbstractAuthenticatorPlugin, BaseAuthenticatorConfiguration
12-
from ansible_base.authentication.social_auth import SocialAuthMixin
12+
from ansible_base.authentication.social_auth import SocialAuthMixin, SocialAuthValidateCallbackMixin
1313
from ansible_base.lib.serializers.fields import BooleanField, CharField, ChoiceField, DictField, IntegerField, ListField, URLField
1414
from ansible_base.lib.utils.settings import get_setting
1515

@@ -90,6 +90,15 @@ class OpenIdConnectConfiguration(BaseAuthenticatorConfiguration):
9090
ui_field_label=_("Authorization URL"),
9191
)
9292

93+
CALLBACK_URL = URLField(
94+
help_text=_(
95+
"Provide this URL as the callback URL for your application as part of your registration process. Refer to the documentation for more detail."
96+
),
97+
required=False,
98+
allow_null=True,
99+
ui_field_label=_("OIDC Callback URL"),
100+
)
101+
93102
ID_KEY = CharField(
94103
help_text=_("The JSON key used to extract the user's ID from the ID token."),
95104
default="sub",
@@ -210,7 +219,7 @@ class OpenIdConnectConfiguration(BaseAuthenticatorConfiguration):
210219
)
211220

212221

213-
class AuthenticatorPlugin(SocialAuthMixin, OpenIdConnectAuth, AbstractAuthenticatorPlugin):
222+
class AuthenticatorPlugin(SocialAuthMixin, SocialAuthValidateCallbackMixin, OpenIdConnectAuth, AbstractAuthenticatorPlugin):
214223
configuration_class = OpenIdConnectConfiguration
215224
type = "open_id_connect"
216225
logger = logger

test_app/tests/authentication/authenticator_plugins/test_oidc.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from ansible_base.authentication.authenticator_plugins.oidc import AuthenticatorPlugin
88
from ansible_base.authentication.session import SessionAuthentication
9-
from ansible_base.lib.utils.response import get_relative_url
9+
from ansible_base.lib.utils.response import get_fully_qualified_url, get_relative_url
1010

1111
authenticated_test_page = "authenticator-list"
1212

@@ -42,6 +42,27 @@ def test_oidc_auth_failed(authenticate, unauthenticated_api_client, oidc_authent
4242
assert response.status_code == 401
4343

4444

45+
def test_oidc_create_via_api_without_callback_url(admin_api_client, oidc_configuration):
46+
del oidc_configuration['CALLBACK_URL']
47+
48+
authenticator_data = {
49+
"name": "Test OIDC Authenticator",
50+
"enabled": True,
51+
"create_objects": True,
52+
"remove_users": True,
53+
"type": "ansible_base.authentication.authenticator_plugins.oidc",
54+
"configuration": oidc_configuration,
55+
}
56+
57+
url = get_relative_url("authenticator-list")
58+
response = admin_api_client.post(url, data=authenticator_data, format="json", SERVER_NAME="dab.example.com")
59+
assert response.status_code == 201, response.data
60+
61+
slug = response.data["slug"]
62+
expected_path = get_fully_qualified_url('social:complete', kwargs={'backend': slug})
63+
assert response.data["configuration"]["CALLBACK_URL"] == f"http://dab.example.com{expected_path}"
64+
65+
4566
@pytest.mark.django_db
4667
@pytest.mark.parametrize(
4768
"endpoint_url, expected_status_code, expected_error",

test_app/tests/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,11 @@ def google_oauth2_authenticator(google_oauth2_configuration):
305305
def oidc_configuration():
306306
return {
307307
"OIDC_ENDPOINT": "https://localhost/api/gateway/callback/oidc_test/",
308-
"OIDC_VERIFY_SSL": True,
308+
"VERIFY_SSL": True,
309309
"KEY": "12345",
310310
"SECRET": "abcdefg12345",
311311
"AUTHORIZATION_URL": "https://oidc.example.com/authorize/",
312+
"CALLBACK_URL": "https://localhost/api/social/complete/ansible_base-authenticator_plugins-oidc__test-oidc-authenticator/",
312313
}
313314

314315

0 commit comments

Comments
 (0)