Skip to content

Commit

Permalink
chore: change backend name (#2479)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anas12091101 authored Dec 17, 2024
1 parent ad5991c commit 0e7d4d3
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 16 deletions.
8 changes: 8 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/source/assets/authentication-flow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions main/management/commands/configure_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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/",
]
)

Expand Down
13 changes: 12 additions & 1 deletion main/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions openedx/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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,
),
Expand Down Expand Up @@ -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()

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

Expand Down
8 changes: 4 additions & 4 deletions openedx/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion openedx/migrations/0001_add_oauth_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 0e7d4d3

Please sign in to comment.