-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add mitxpro-social-auth (#376)
* feat: add mitxpro-social-auth * fix: github CI * fix: test * fix: precommit errors * fix: Update and rename README.md to README.rst * fix: issues * fix: issues * fix: issues * fix: fixed install dependencies issue
- Loading branch information
1 parent
6abb6fe
commit 3f54ed4
Showing
14 changed files
with
349 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
python_sources( | ||
name="ol_social_auth_source", | ||
dependencies=["//:external_dependencies#social-auth-core"] | ||
) | ||
|
||
python_distribution( | ||
name="ol_social_auth_package", | ||
dependencies=[ | ||
":ol_social_auth_source", | ||
], | ||
provides=setup_py( | ||
name="ol-social-auth", | ||
version="0.1.0", | ||
description="An Open edX plugin implementing MIT social auth backend", | ||
license="BSD-3-Clause", | ||
author="MIT Office of Digital Learning", | ||
include_package_data=True, | ||
zip_safe=False, | ||
keywords="Python edx" | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
Copyright (C) 2022 MIT Open Learning | ||
|
||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
* Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
Open Learning Social Auth | ||
======================= | ||
|
||
An Open edX plugin implementing MIT social auth backend | ||
|
||
Version Compatibility | ||
--------------------- | ||
|
||
Compatible with all edx releases | ||
|
||
Installing The Plugin | ||
--------------------- | ||
|
||
You can install this plugin into any Open edX instance by using any of the following methods: | ||
|
||
**Option 1: Install from PyPI** | ||
|
||
.. code-block:: | ||
# If running devstack in docker, first open a shell in LMS (make lms-shell) | ||
pip install ol-social-auth | ||
**Option 2: Build the package locally and install it** | ||
|
||
Follow these steps in a terminal on your machine: | ||
|
||
1. Navigate to ``open-edx-plugins`` directory | ||
2. If you haven't done so already, run ``./pants build`` | ||
3. Run ``./pants package ::``. This will create a "dist" directory inside "open-edx-plugins" directory with ".whl" & ".tar.gz" format packages for all plugins in the src directory | ||
4. Move/copy any of the ".whl" or ".tar.gz" files for this plugin that were generated in the above step to the machine/container running Open edX (NOTE: If running devstack via Docker, you can use ``docker cp`` to copy these files into your LMS or CMS containers) | ||
5. Run a shell in the machine/container running Open edX, and install this plugin using pip | ||
|
||
|
||
``Note``: In some cases you might need to restart edx-platform after installing the plugin to reflect the changes. | ||
|
||
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>`_ | ||
|
||
|
||
How to use | ||
---------- | ||
Make sure to properly configure the plugin following the links in the above "Configurations" section before use. | ||
* Install the plugin in the lms following the installation steps above. | ||
* Verify that you are not logged in on edx-platform. | ||
* Create a new user in your MIT application and verify that a corresponding user is successfully created on the edX platform. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
"""MIT xPro social auth backend""" | ||
|
||
from social_core.backends.oauth import BaseOAuth2 | ||
|
||
|
||
class MITxProOAuth2(BaseOAuth2): | ||
"""MIT xPro social auth backend""" | ||
|
||
name = "mitxpro-oauth2" | ||
|
||
ID_KEY = "username" | ||
REQUIRES_EMAIL_VALIDATION = False | ||
|
||
ACCESS_TOKEN_METHOD = "POST" # noqa: S105 | ||
|
||
# at a minimum we need to be able to read the user | ||
DEFAULT_SCOPE = ["user:read"] | ||
|
||
def authorization_url(self): | ||
"""Provides authorization_url from settings""" # noqa: D401 | ||
return self.setting("AUTHORIZATION_URL") | ||
|
||
def access_token_url(self): | ||
"""Provides access_token_url from settings""" # noqa: D401 | ||
return self.setting("ACCESS_TOKEN_URL") | ||
|
||
def api_root(self): | ||
"""Returns the API root as configured""" # noqa: D401 | ||
root = self.setting("API_ROOT") | ||
|
||
if root and root[-1] != "/": | ||
root = f"{root}/" | ||
|
||
return root | ||
|
||
def auth_html(self): # pragma: no cover | ||
"""No html for this provider""" | ||
# NOTE: this is only here to stop the pylint warning about this abstract | ||
# method not being overridden without disabling it for the entire class | ||
return "" | ||
|
||
def api_url(self, path): | ||
""" | ||
Returns the full api url given a relative path | ||
Args: | ||
path (str): relative api path | ||
""" # noqa: D401 | ||
return f"{self.api_root()}{path}" | ||
|
||
def get_user_details(self, response): | ||
"""Return user details from xPro 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 | ||
url = self.api_url("api/users/me") | ||
headers = {"Authorization": f"Bearer {access_token}"} | ||
return self.get_json(url, headers=headers) |
Empty file.
Oops, something went wrong.