Skip to content

Commit

Permalink
feat: change backend name of social auth (#388)
Browse files Browse the repository at this point in the history
* feat: change backend name of social auth

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

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

* docs: updated doc strings

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Muhammad Anas <[email protected]>
  • Loading branch information
3 people authored Nov 25, 2024
1 parent a11d096 commit 0fd7824
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 15 deletions.
5 changes: 2 additions & 3 deletions src/ol_social_auth/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ Configurations
--------------
This section outlines the steps for integrating your application with ol-social-auth for various deployment scenarios. Please refer to the corresponding documentation for detailed instructions.

* **MITxPRO:** To configure ol-social-auth with MITxPRO, follow the comprehensive guide available `here <https://github.com/mitodl/mitxpro/blob/master/docs/configure_open_edx.md>`_
* **MITxOnline:** For integration with MITxOnline, detailed instructions can be found in the official documentation `here <https://github.com/mitodl/mitxonline/blob/main/docs/source/configuration/open_edx.rst>`_
* **MITxOnline with Tutor:** If you're using MITxOnline with Tutor for development purposes, specific configuration steps are outlined in the `documentation <https://github.com/mitodl/mitxonline/blob/main/docs/source/configuration/tutor.rst>`_
* **Devstack:** To configure ol-social-auth with an edx-platform instance provisioned using devstack, follow the instructions `here <https://mitodl.github.io/handbook/openedx/MITx-edx-integration-devstack.html>`_
* **Tutor:** To configure ol-social-auth with an edx-platform instance provisioned using tutor, follow the instructions `here https://mitodl.github.io/handbook/openedx/MITx-edx-integration-tutor.html`_


How to use
Expand Down
12 changes: 6 additions & 6 deletions src/ol_social_auth/backends.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""MIT xPro social auth backend"""
"""Open Learning social auth backend"""

from social_core.backends.oauth import BaseOAuth2


class MITxProOAuth2(BaseOAuth2):
"""MIT xPro social auth backend"""
class OLOAuth2(BaseOAuth2):
"""Open Learning social auth backend"""

name = "mitxpro-oauth2"
name = "ol-oauth2"

ID_KEY = "username"
REQUIRES_EMAIL_VALIDATION = False
Expand Down Expand Up @@ -49,15 +49,15 @@ def api_url(self, path):
return f"{self.api_root()}{path}"

def get_user_details(self, response):
"""Return user details from xPro account"""
"""Return user details from MIT application account"""
return {
"username": response.get("username"),
"email": response.get("email", ""),
"name": response.get("name", ""),
}

def user_data(self, access_token, *args, **kwargs): # noqa: ARG002
"""Loads user data from xpro""" # noqa: D401
"""Loads user data from MIT application""" # noqa: D401
url = self.api_url("api/users/me")
headers = {"Authorization": f"Bearer {access_token}"}
return self.get_json(url, headers=headers)
6 changes: 3 additions & 3 deletions src/ol_social_auth/tests/backends_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from urllib.parse import urljoin

import pytest
from ol_social_auth.backends import MITxProOAuth2
from ol_social_auth.backends import OLOAuth2

# pylint: disable=redefined-outer-name

Expand All @@ -16,8 +16,8 @@ def strategy(mocker):

@pytest.fixture()
def backend(strategy):
"""MITxProOAuth2 backend fixture"""
return MITxProOAuth2(strategy)
"""OLOAuth2 backend fixture"""
return OLOAuth2(strategy)


@pytest.mark.parametrize(
Expand Down
2 changes: 1 addition & 1 deletion src/openedx_companion_auth/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
def plugin_settings(settings):
"""Apply default settings for this plugin"""
settings.MITX_REDIRECT_ENABLED = True
settings.MITX_REDIRECT_LOGIN_URL = "/auth/login/mitxpro-oauth2/?auth_entry=login"
settings.MITX_REDIRECT_LOGIN_URL = "/auth/login/ol-oauth2/?auth_entry=login"
settings.MITX_REDIRECT_ALLOW_RE_LIST = [
r"^/(admin|auth|login|logout|register|api|oauth2|user_api)"
]
Expand Down
2 changes: 1 addition & 1 deletion src/openedx_companion_auth/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def plugin_settings( # type: ignore[no-redef]
Configure the plugin for tests
"""
settings.MITX_REDIRECT_ENABLED = True
settings.MITX_REDIRECT_LOGIN_URL = "/auth/login/mitxpro-oauth2/?auth_entry=login"
settings.MITX_REDIRECT_LOGIN_URL = "/auth/login/ol-oauth2/?auth_entry=login"
settings.MITX_REDIRECT_ALLOW_RE_LIST = [
r"^/(admin|auth|login|logout|register|api|oauth2|user_api)"
]
Expand Down
2 changes: 1 addition & 1 deletion src/openedx_companion_auth/tests/middleware_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_redirect_middleware( # noqa: PLR0913
should_redirect,
): # pylint: disable=too-many-arguments
"""Test that the middleware redirects correctly"""
settings.MITX_REDIRECT_LOGIN_URL = "/mitxpro-oauth2/?auth_entry=login"
settings.MITX_REDIRECT_LOGIN_URL = "/ol-oauth2/?auth_entry=login"
settings.MITX_REDIRECT_ENABLED = is_enabled
settings.MITX_REDIRECT_ALLOW_RE_LIST = allowed_regexes
settings.MITX_REDIRECT_DENY_RE_LIST = denied_regexes
Expand Down

0 comments on commit 0fd7824

Please sign in to comment.