Skip to content

Commit

Permalink
chore: change backend name (#3327)
Browse files Browse the repository at this point in the history
* chore: change backend name

* fix: tests

* config: add MITXPRO_OAUTH_PROVIDER and OPENEDX_SOCIAL_LOGIN_PATH in env

* fix: settings

* fix: settings

* fix: settings

* config: rename MITXPRO_OAUTH_PROVIDER to OPENEDX_OAUTH_PROVIDER

* chore: removed configure_open_edx.md

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Anas12091101 and pre-commit-ci[bot] authored Dec 6, 2024
1 parent 1a6ba22 commit 2654f1d
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 191 deletions.
8 changes: 8 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,10 @@
"description": "The 'name' value for the Open edX OAuth Application",
"required": true
},
"OPENEDX_OAUTH_PROVIDER": {
"description": "Social auth oauth provider backend name",
"required": false
},
"OPENEDX_SERVICE_WORKER_API_TOKEN": {
"description": "Active access token with staff level permissions to use with OpenEdX API client for service tasks",
"required": false
Expand All @@ -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
9 changes: 4 additions & 5 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_XPRO_PATH = "/auth/login/mitxpro-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 @@ -194,7 +193,7 @@ def create_edx_user(user):
username=user.username,
email=user.email,
name=user.name,
provider=settings.MITXPRO_OAUTH_PROVIDER,
provider=settings.OPENEDX_OAUTH_PROVIDER,
access_token=access_token.token,
**OPENEDX_REQUEST_DEFAULTS,
),
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_XPRO_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_XPRO_PATH)
url = edx_url(settings.OPENEDX_SOCIAL_LOGIN_PATH)
resp = req_session.get(url)
resp.raise_for_status()

Expand Down Expand Up @@ -815,7 +814,7 @@ def create_oauth_application():
defaults=dict( # noqa: C408
redirect_uris=urljoin(
settings.OPENEDX_BASE_REDIRECT_URL,
f"/auth/complete/{settings.MITXPRO_OAUTH_PROVIDER}/",
f"/auth/complete/{settings.OPENEDX_OAUTH_PROVIDER}/",
),
client_type="confidential",
authorization_grant_type="authorization-code",
Expand Down
8 changes: 4 additions & 4 deletions courseware/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,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.MITXPRO_OAUTH_PROVIDER = "test_provider"
settings.OPENEDX_OAUTH_PROVIDER = "test_provider"
settings.MITXPRO_REGISTRATION_ACCESS_TOKEN = "access_token" # noqa: S105
return Application.objects.create(
name=settings.OPENEDX_OAUTH_APP_NAME,
Expand Down 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/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 @@ -243,7 +243,7 @@ def test_create_edx_user(user, settings, application, access_token_count):
"username": user.username,
"email": user.email,
"name": user.name,
"provider": settings.MITXPRO_OAUTH_PROVIDER,
"provider": settings.OPENEDX_OAUTH_PROVIDER,
"access_token": created_access_token.token,
"country": "US",
"honor_code": "True",
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/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
177 changes: 0 additions & 177 deletions docs/configure_open_edx.md

This file was deleted.

8 changes: 4 additions & 4 deletions mitxpro/management/commands/configure_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,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 @@ -129,8 +129,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 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 = "mitxpro-oauth2"
OPENEDX_OAUTH_PROVIDER = get_string(
name="OPENEDX_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 2654f1d

Please sign in to comment.