Skip to content

Commit

Permalink
config: add MITXPRO_OAUTH_PROVIDER and OPENEDX_SOCIAL_LOGIN_PATH in env
Browse files Browse the repository at this point in the history
  • Loading branch information
Anas12091101 committed Dec 5, 2024
1 parent f64e125 commit 9973fa2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
24 changes: 16 additions & 8 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions courseware/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions courseware/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
13 changes: 12 additions & 1 deletion mitxpro/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 9973fa2

Please sign in to comment.