From 0e7d4d3316a5a9064c0d93eab65f6bf86346c34c Mon Sep 17 00:00:00 2001 From: Muhammad Anas <88967643+Anas12091101@users.noreply.github.com> Date: Tue, 17 Dec 2024 17:08:15 +0500 Subject: [PATCH] chore: change backend name (#2479) --- app.json | 8 ++++++++ docs/source/assets/authentication-flow.mm | 4 ++-- main/management/commands/configure_instance.py | 8 ++++---- main/settings.py | 13 ++++++++++++- openedx/api.py | 8 ++++---- openedx/api_test.py | 8 ++++---- openedx/migrations/0001_add_oauth_application.py | 2 +- 7 files changed, 35 insertions(+), 16 deletions(-) diff --git a/app.json b/app.json index 09c4236624..4c2bf7ca6a 100644 --- a/app.json +++ b/app.json @@ -497,6 +497,10 @@ "description": "The 'name' value for the Open edX OAuth Application", "required": true }, + "OPENEDX_OAUTH_PROVIDER": { + "description": "Social auth provider backend name", + "required": false + }, "OPENEDX_RETIREMENT_SERVICE_WORKER_CLIENT_ID": { "description": "OAuth2 client id for retirement service worker", "required": false @@ -513,6 +517,10 @@ "description": "Username of the user whose token has been set in OPENEDX_SERVICE_WORKER_API_TOKEN", "required": false }, + "OPENEDX_SOCIAL_LOGIN_PATH": { + "description": "Open edX social auth login url", + "required": false + }, "OPENEDX_TOKEN_EXPIRES_HOURS": { "description": "The number of hours until an access token for the Open edX API expires", "required": false diff --git a/docs/source/assets/authentication-flow.mm b/docs/source/assets/authentication-flow.mm index 7c75f42310..9fedf59746 100644 --- a/docs/source/assets/authentication-flow.mm +++ b/docs/source/assets/authentication-flow.mm @@ -10,9 +10,9 @@ par Create Open edX Access Token Note right of MO: Create in-memory requests session par Establish an Open edX session - MO->>OE: GET /auth/login/mitxpro-oauth2/?auth_entry=login + MO->>OE: GET /auth/login/ol-oauth2/?auth_entry=login OE->>MO: Redirect to GET /oauth2/authorize - MO->>OE: Redirect to GET /auth/complete/mitxpro-oauth2/ + MO->>OE: Redirect to GET /auth/complete/ol-oauth2/ end par Link MITx Online account to Open edX Account diff --git a/main/management/commands/configure_instance.py b/main/management/commands/configure_instance.py index 60209bb711..d68bd32b35 100644 --- a/main/management/commands/configure_instance.py +++ b/main/management/commands/configure_instance.py @@ -152,8 +152,8 @@ def handle(self, *args, **kwargs): # noqa: ARG002 if kwargs["platform"] == "macos": redirects = "\n".join( [ - f"http://{edx_host}/auth/complete/mitxpro-oauth2/", - f"http://host.docker.internal{edx_gateway_port}/auth/complete/mitxpro-oauth2/", + f"http://{edx_host}/auth/complete/ol-oauth2/", + f"http://host.docker.internal{edx_gateway_port}/auth/complete/ol-oauth2/", ] ) else: @@ -167,8 +167,8 @@ def handle(self, *args, **kwargs): # noqa: ARG002 redirects = "\n".join( [ - f"http://{edx_host}/auth/complete/mitxpro-oauth2/", - f"http://{kwargs['gateway']}{edx_gateway_port}/auth/complete/mitxpro-oauth2/", + f"http://{edx_host}/auth/complete/ol-oauth2/", + f"http://{kwargs['gateway']}{edx_gateway_port}/auth/complete/ol-oauth2/", ] ) diff --git a/main/settings.py b/main/settings.py index 456e0149ea..45f06d443f 100644 --- a/main/settings.py +++ b/main/settings.py @@ -980,7 +980,18 @@ MITOL_AUTHENTICATION_FROM_EMAIL = MAILGUN_FROM_EMAIL MITOL_AUTHENTICATION_REPLY_TO_EMAIL = MITX_ONLINE_REPLY_TO_ADDRESS -MITX_ONLINE_OAUTH_PROVIDER = "mitxpro-oauth2" +OPENEDX_OAUTH_PROVIDER = get_string( + name="OPENEDX_OAUTH_PROVIDER", + default="mitxpro-oauth2", + description="Social auth provider backend name", +) + +OPENEDX_SOCIAL_LOGIN_PATH = get_string( + name="OPENEDX_SOCIAL_LOGIN_PATH", + default="/auth/login/mitxpro-oauth2/?auth_entry=login", + description="Open edX social auth login url", +) + OPENEDX_OAUTH_APP_NAME = get_string( name="OPENEDX_OAUTH_APP_NAME", default="edx-oauth-app", diff --git a/openedx/api.py b/openedx/api.py index 05d8b05633..777745a1a0 100644 --- a/openedx/api.py +++ b/openedx/api.py @@ -53,7 +53,7 @@ OPENEDX_UPDATE_USER_PATH = "/api/user/v1/accounts/" OPENEDX_REQUEST_DEFAULTS = dict(honor_code=True) # noqa: C408 -OPENEDX_SOCIAL_LOGIN_XPRO_PATH = "/auth/login/mitxpro-oauth2/?auth_entry=login" +OPENEDX_SOCIAL_LOGIN_PATH = settings.OPENEDX_SOCIAL_LOGIN_PATH OPENEDX_OAUTH2_AUTHORIZE_PATH = "/oauth2/authorize" OPENEDX_OAUTH2_ACCESS_TOKEN_PATH = "/oauth2/access_token" # noqa: S105 OPENEDX_OAUTH2_SCOPES = ["read", "write"] @@ -130,7 +130,7 @@ def create_edx_user(user): level_of_education=user.user_profile.level_of_education if user.user_profile else None, - provider=settings.MITX_ONLINE_OAUTH_PROVIDER, + provider=settings.OPENEDX_OAUTH_PROVIDER, access_token=access_token.token, **OPENEDX_REQUEST_DEFAULTS, ), @@ -186,7 +186,7 @@ def create_edx_auth_token(user): req_session.cookies.set_cookie(session_cookie) # Step 3 - url = edx_url(OPENEDX_SOCIAL_LOGIN_XPRO_PATH) + url = edx_url(OPENEDX_SOCIAL_LOGIN_PATH) resp = req_session.get(url) resp.raise_for_status() @@ -283,7 +283,7 @@ def update_edx_user_email(user): ) req_session.cookies.set_cookie(session_cookie) - url = edx_url(OPENEDX_SOCIAL_LOGIN_XPRO_PATH) + url = edx_url(OPENEDX_SOCIAL_LOGIN_PATH) resp = req_session.get(url) resp.raise_for_status() diff --git a/openedx/api_test.py b/openedx/api_test.py index 182bddc0ea..a9f568ac0b 100644 --- a/openedx/api_test.py +++ b/openedx/api_test.py @@ -72,7 +72,7 @@ def application(settings): """Test data and settings needed for create_edx_user tests""" settings.OPENEDX_OAUTH_APP_NAME = "test_app_name" settings.OPENEDX_API_BASE_URL = "http://example.com" - settings.MITX_ONLINE_OAUTH_PROVIDER = "test_provider" + settings.OPENEDX_OAUTH_PROVIDER = "test_provider" settings.MITX_ONLINE_REGISTRATION_ACCESS_TOKEN = "access_token" # noqa: S105 return Application.objects.create( name=settings.OPENEDX_OAUTH_APP_NAME, @@ -155,7 +155,7 @@ def test_create_edx_user(user, settings, application, access_token_count): "username": user.username, "email": user.email, "name": user.name, - "provider": settings.MITX_ONLINE_OAUTH_PROVIDER, + "provider": settings.OPENEDX_OAUTH_PROVIDER, "access_token": created_access_token.token, "country": user.legal_address.country if user.legal_address else None, "year_of_birth": str(user.user_profile.year_of_birth) @@ -261,7 +261,7 @@ def test_create_edx_auth_token(settings, user): code = "ghi789" responses.add( responses.GET, - f"{settings.OPENEDX_API_BASE_URL}/auth/login/mitxpro-oauth2/?auth_entry=login", + f"{settings.OPENEDX_API_BASE_URL}{settings.OPENEDX_SOCIAL_LOGIN_PATH}", status=status.HTTP_200_OK, ) responses.add( @@ -337,7 +337,7 @@ def test_update_edx_user_email(settings, user): code = "ghi789" responses.add( responses.GET, - f"{settings.OPENEDX_API_BASE_URL}/auth/login/mitxpro-oauth2/?auth_entry=login", + f"{settings.OPENEDX_API_BASE_URL}{settings.OPENEDX_SOCIAL_LOGIN_PATH}", status=status.HTTP_200_OK, ) responses.add( diff --git a/openedx/migrations/0001_add_oauth_application.py b/openedx/migrations/0001_add_oauth_application.py index ad0658ba3c..1976da40b6 100644 --- a/openedx/migrations/0001_add_oauth_application.py +++ b/openedx/migrations/0001_add_oauth_application.py @@ -14,7 +14,7 @@ def create_edx_oauth_application(apps, schema_editor): defaults=dict( # noqa: C408 redirect_uris=urljoin( settings.OPENEDX_BASE_REDIRECT_URL, - f"/auth/complete/{settings.MITX_ONLINE_OAUTH_PROVIDER}/", + f"/auth/complete/{settings.OPENEDX_OAUTH_PROVIDER}/", ), client_type="confidential", authorization_grant_type="authorization-code",