From 7046fd6a18f50c455778a9824e4ac757d7c4e87a Mon Sep 17 00:00:00 2001 From: Muhammad Anas Date: Thu, 5 Dec 2024 18:34:58 +0500 Subject: [PATCH] config: add MITXPRO_OAUTH_PROVIDER and OPENEDX_SOCIAL_LOGIN_PATH in env --- app.json | 24 ++++++++++++++++-------- courseware/api.py | 5 ++--- courseware/api_test.py | 4 ++-- mitxpro/settings.py | 13 ++++++++++++- 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/app.json b/app.json index c6e7311f8..599fbc647 100644 --- a/app.json +++ b/app.json @@ -234,22 +234,22 @@ "description": "Timeout (in seconds) for requests made via the edX API client", "required": false }, - "EMERITUS_API_BASE_URL": { + "ENROLLMENT_CHANGE_SHEET_ID": { + "description": "ID of the Google Sheet that contains the enrollment change request worksheets (refunds, transfers, etc)", + "required": false + }, + "EXTERNAL_COURSE_SYNC_API_BASE_URL": { "description": "Base API URL for Emeritus API", "required": false }, - "EMERITUS_API_KEY": { - "description": "The API Key for Emeritus API", + "EXTERNAL_COURSE_SYNC_API_KEY": { + "description": "The API Key for EXTERNAL_COURSE_SYNC API", "required": true }, - "EMERITUS_API_TIMEOUT": { + "EXTERNAL_COURSE_SYNC_API_TIMEOUT": { "description": "API request timeout for Emeritus APIs in seconds", "required": false }, - "ENROLLMENT_CHANGE_SHEET_ID": { - "description": "ID of the Google Sheet that contains the enrollment change request worksheets (refunds, transfers, etc)", - "required": false - }, "GA_TRACKING_ID": { "description": "Google analytics tracking ID", "required": false @@ -430,6 +430,10 @@ "description": "The email backend to use for application emails", "required": false }, + "MITXPRO_OAUTH_PROVIDER": { + "description": "Social auth oauth provider backend name", + "required": false + }, "MITXPRO_REGISTRATION_ACCESS_TOKEN": { "description": "Access token to secure Open edX registration API with", "required": false @@ -490,6 +494,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/courseware/api.py b/courseware/api.py index 56efad7c5..dd21cc3c5 100644 --- a/courseware/api.py +++ b/courseware/api.py @@ -52,7 +52,6 @@ OPENEDX_REGISTER_USER_PATH = "/user_api/v1/account/registration/" OPENEDX_REQUEST_DEFAULTS = dict(country="US", honor_code=True) # noqa: C408 -OPENEDX_SOCIAL_LOGIN_PATH = "/auth/login/ol-oauth2/?auth_entry=login" OPENEDX_OAUTH2_AUTHORIZE_PATH = "/oauth2/authorize" OPENEDX_OAUTH2_ACCESS_TOKEN_PATH = "/oauth2/access_token" # noqa: S105 OPENEDX_OAUTH2_SCOPES = ["read", "write"] @@ -256,7 +255,7 @@ def create_edx_auth_token(user): req_session.cookies.set_cookie(session_cookie) # Step 3 - url = edx_url(OPENEDX_SOCIAL_LOGIN_PATH) + url = edx_url(settings.OPENEDX_SOCIAL_LOGIN_PATH) resp = req_session.get(url) resp.raise_for_status() @@ -316,7 +315,7 @@ def update_edx_user_email(user): ) req_session.cookies.set_cookie(session_cookie) - url = edx_url(OPENEDX_SOCIAL_LOGIN_PATH) + url = edx_url(settings.OPENEDX_SOCIAL_LOGIN_PATH) resp = req_session.get(url) resp.raise_for_status() diff --git a/courseware/api_test.py b/courseware/api_test.py index 374d871d3..479cc927d 100644 --- a/courseware/api_test.py +++ b/courseware/api_test.py @@ -174,7 +174,7 @@ def create_token_responses(settings): code = "ghi789" responses.add( responses.GET, - f"{settings.OPENEDX_API_BASE_URL}/auth/login/ol-oauth2/?auth_entry=login", + f"{settings.OPENEDX_API_BASE_URL}{settings.OPENEDX_SOCIAL_LOGIN_PATH}", status=status.HTTP_200_OK, ) responses.add( @@ -350,7 +350,7 @@ def test_update_edx_user_email(settings, user): code = "ghi789" responses.add( responses.GET, - f"{settings.OPENEDX_API_BASE_URL}/auth/login/ol-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/mitxpro/settings.py b/mitxpro/settings.py index bfcaec6e4..b5fe92900 100644 --- a/mitxpro/settings.py +++ b/mitxpro/settings.py @@ -1070,7 +1070,18 @@ MITOL_AUTHENTICATION_REPLY_TO_EMAIL = MITXPRO_REPLY_TO_ADDRESS -MITXPRO_OAUTH_PROVIDER = "ol-oauth2" +MITXPRO_OAUTH_PROVIDER = get_string( + name="MITXPRO_OAUTH_PROVIDER", + default="mitxpro-oauth2", + description="Social auth oauth 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",