Compare commits
No commits in common. "main" and "v1.0.2" have entirely different histories.
7
.pre-commit-config.yaml
Normal file
7
.pre-commit-config.yaml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
repos:
|
||||||
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
|
rev: v2.3.0
|
||||||
|
hooks:
|
||||||
|
- id: check-yaml
|
||||||
|
- id: end-of-file-fixer
|
||||||
|
- id: trailing-whitespace
|
40
Makefile
40
Makefile
@ -1,40 +0,0 @@
|
|||||||
# -------------------------------------------------------------------------
|
|
||||||
# build a package for PyPi
|
|
||||||
# -------------------------------------------------------------------------
|
|
||||||
.PHONY: build
|
|
||||||
.PHONY: requirements
|
|
||||||
|
|
||||||
report:
|
|
||||||
cloc $(git ls-files)
|
|
||||||
|
|
||||||
build:
|
|
||||||
python3 -m pip install --upgrade setuptools wheel twine
|
|
||||||
python3 -m pip install --upgrade build
|
|
||||||
|
|
||||||
if [ -d "./build" ]; then sudo rm -r build; fi
|
|
||||||
if [ -d "./dist" ]; then sudo rm -r dist; fi
|
|
||||||
if [ -d "./edx_oauth2_wordpress_backend.egg-info" ]; then sudo rm -r edx_oauth2_wordpress_backend.egg-info; fi
|
|
||||||
|
|
||||||
python3 -m build --sdist ./
|
|
||||||
python3 -m build --wheel ./
|
|
||||||
|
|
||||||
python3 -m pip install --upgrade twine
|
|
||||||
twine check dist/*
|
|
||||||
|
|
||||||
|
|
||||||
# -------------------------------------------------------------------------
|
|
||||||
# upload to PyPi Test
|
|
||||||
# https:// ?????
|
|
||||||
# -------------------------------------------------------------------------
|
|
||||||
release-test:
|
|
||||||
make build
|
|
||||||
twine upload --skip-existing --repository testpypi dist/*
|
|
||||||
|
|
||||||
|
|
||||||
# -------------------------------------------------------------------------
|
|
||||||
# upload to PyPi
|
|
||||||
# https://pypi.org/project/django-memberpress-client/
|
|
||||||
# -------------------------------------------------------------------------
|
|
||||||
release-prod:
|
|
||||||
make build
|
|
||||||
twine upload --skip-existing dist/*
|
|
101
README.rst
101
README.rst
@ -1,9 +1,5 @@
|
|||||||
Open edX OAuth2 Backend for Wordpress
|
Wordpress OAuth2 Backend for Open edX
|
||||||
=====================================
|
=====================================
|
||||||
.. image:: https://img.shields.io/static/v1?label=pypi&style=flat-square&color=0475b6&message=edx-oauth2-wordpress-backend
|
|
||||||
:alt: PyPi edx-oauth2-wordpress-backend
|
|
||||||
:target: https://pypi.org/project/edx-oauth2-wordpress-backend/
|
|
||||||
|
|
||||||
.. image:: https://img.shields.io/badge/hack.d-Lawrence%20McDaniel-orange.svg
|
.. image:: https://img.shields.io/badge/hack.d-Lawrence%20McDaniel-orange.svg
|
||||||
:target: https://lawrencemcdaniel.com
|
:target: https://lawrencemcdaniel.com
|
||||||
:alt: Hack.d Lawrence McDaniel
|
:alt: Hack.d Lawrence McDaniel
|
||||||
@ -22,7 +18,7 @@ Open edX OAuth2 Backend for Wordpress
|
|||||||
Overview
|
Overview
|
||||||
--------
|
--------
|
||||||
|
|
||||||
An Open edX oauth2 backend for `Wordpress <https://wordpress.org//>`_ `WP OAuth Server <https://wp-oauth.com/>`_.
|
A Python Social Auth backend for `WP OAuth <https://wp-oauth.com/>`_ this is customized for use with Open edX.
|
||||||
|
|
||||||
- `Python Social Auth custom backend implentation <https://python-social-auth.readthedocs.io/en/latest/backends/implementation.html>`_
|
- `Python Social Auth custom backend implentation <https://python-social-auth.readthedocs.io/en/latest/backends/implementation.html>`_
|
||||||
- `WP Oauth Wordpress Plugin Documentation <https://wp-oauth.com/docs/>`_
|
- `WP Oauth Wordpress Plugin Documentation <https://wp-oauth.com/docs/>`_
|
||||||
@ -40,20 +36,22 @@ An example implementation for an Open edX installation named https://stepwisemat
|
|||||||
1. add this package to your project's requiremets
|
1. add this package to your project's requiremets
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
add this package to your project's requiremets.txt, or install it from the command line.
|
include this repo in your project's requiremets.txt, or install it from the command line.
|
||||||
|
|
||||||
.. code-block:: shell
|
.. code-block:: shell
|
||||||
|
|
||||||
pip install edx-oauth2-wordpress-backend
|
cd path/to/your/virtual/environment
|
||||||
|
source path/to/venv/bin/activate
|
||||||
|
pip install https://github.com/lpm0073/wp-oauth-backend
|
||||||
|
|
||||||
2. subclass WPOpenEdxOAuth2
|
2. subclass WPOpenEdxOAuth2
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
Subclass oauth2_wordpress.wp_oauth.WPOpenEdxOAuth2, and configure for your Wordpress oauth provider.
|
Subclass wp_oauth_backend.wp_oauth.WPOpenEdxOAuth2, and configure for your Wordpress oauth provider.
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
from oauth2_wordpress.wp_oauth import WPOpenEdxOAuth2
|
from wp_oauth_backend.wp_oauth import WPOpenEdxOAuth2
|
||||||
|
|
||||||
|
|
||||||
class StepwiseMathWPOAuth2(WPOpenEdxOAuth2):
|
class StepwiseMathWPOAuth2(WPOpenEdxOAuth2):
|
||||||
@ -69,14 +67,7 @@ Subclass oauth2_wordpress.wp_oauth.WPOpenEdxOAuth2, and configure for your Wordp
|
|||||||
|
|
||||||
# note: no slash at the end of the base url. Python Social Auth
|
# note: no slash at the end of the base url. Python Social Auth
|
||||||
# might clean this up for you, but i'm not 100% certain of that.
|
# might clean this up for you, but i'm not 100% certain of that.
|
||||||
#
|
|
||||||
# the following will create an authorization url of https://stepwisemath.ai/wp-json/moserver/authorize
|
|
||||||
BASE_URL = "https://stepwisemath.ai"
|
BASE_URL = "https://stepwisemath.ai"
|
||||||
PATH = "wp-json/moserver/"
|
|
||||||
AUTHORIZATION_ENDPOINT = "authorize"
|
|
||||||
TOKEN_ENDPOINT = "token"
|
|
||||||
USERINFO_ENDPOINT = "resource"
|
|
||||||
|
|
||||||
|
|
||||||
3. configure your Open edX lms application
|
3. configure your Open edX lms application
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
@ -84,9 +75,9 @@ Subclass oauth2_wordpress.wp_oauth.WPOpenEdxOAuth2, and configure for your Wordp
|
|||||||
.. code-block:: yaml
|
.. code-block:: yaml
|
||||||
|
|
||||||
ADDL_INSTALLED_APPS:
|
ADDL_INSTALLED_APPS:
|
||||||
- "oauth2_wordpress"
|
- "wp_oauth_backend"
|
||||||
THIRD_PARTY_AUTH_BACKENDS:
|
THIRD_PARTY_AUTH_BACKENDS:
|
||||||
- "oauth2_wordpress.wp_oauth.StepwiseMathWPOAuth2"
|
- "wp_oauth_backend.wp_oauth.StepwiseMathWPOAuth2"
|
||||||
ENABLE_REQUIRE_THIRD_PARTY_AUTH: true
|
ENABLE_REQUIRE_THIRD_PARTY_AUTH: true
|
||||||
|
|
||||||
add these settings to django.conf:
|
add these settings to django.conf:
|
||||||
@ -100,9 +91,9 @@ add these settings to django.conf:
|
|||||||
* - WPOAUTH_BACKEND_BASE_URL
|
* - WPOAUTH_BACKEND_BASE_URL
|
||||||
- https://stepwisemath.ai
|
- https://stepwisemath.ai
|
||||||
* - WPOAUTH_BACKEND_CLIENT_ID
|
* - WPOAUTH_BACKEND_CLIENT_ID
|
||||||
- see: https://stepwisemath.ai/wp-admin/admin.php?page=mo_oauth_server_settings
|
- see: https://stepwisemath.ai/wp-admin/admin.php?page=wo_manage_clients
|
||||||
* - WPOAUTH_BACKEND_CLIENT_SECRET
|
* - WPOAUTH_BACKEND_CLIENT_SECRET
|
||||||
- see: https://stepwisemath.ai/wp-admin/admin.php?page=mo_oauth_server_settings
|
- see: https://stepwisemath.ai/wp-admin/admin.php?page=wo_manage_clients
|
||||||
* - SCOPE
|
* - SCOPE
|
||||||
- basic email profile
|
- basic email profile
|
||||||
* - GRANT_TYPE
|
* - GRANT_TYPE
|
||||||
@ -113,15 +104,31 @@ add these settings to django.conf:
|
|||||||
4. Configure a new Oauth2 client from the lms Django Admin console
|
4. Configure a new Oauth2 client from the lms Django Admin console
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
.. image:: https://raw.githubusercontent.com/lpm0073/edx-oauth2-wordpress-backend/main/doc/django-admin-1.png
|
.. image:: https://raw.githubusercontent.com/lpm0073/wp-oauth-backend/main/doc/django-admin-1.png
|
||||||
:width: 100%
|
:width: 100%
|
||||||
:alt: Open edX Django Admin Add Provider Configuration (OAuth)
|
:alt: Open edX Django Admin Add Provider Configuration (OAuth)
|
||||||
|
|
||||||
.. image:: https://raw.githubusercontent.com/lpm0073/edx-oauth2-wordpress-backend/main/doc/django-admin-2.png
|
.. image:: https://raw.githubusercontent.com/lpm0073/wp-oauth-backend/main/doc/django-admin-2.png
|
||||||
:width: 100%
|
:width: 100%
|
||||||
:alt: Open edX Django Admin Add Provider Configuration (OAuth)
|
:alt: Open edX Django Admin Add Provider Configuration (OAuth)
|
||||||
|
|
||||||
|
|
||||||
|
5. Configure your devops
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Cookiecutter openedx_devops build
|
||||||
|
|
||||||
|
.. code-block:: shell
|
||||||
|
|
||||||
|
- name: Add the wp-oauth-backend
|
||||||
|
uses: openedx-actions/tutor-plugin-build-openedx-add-requirement@v1.0.0
|
||||||
|
with:
|
||||||
|
repository: wp-oauth-backend
|
||||||
|
repository-organization: StepwiseMath
|
||||||
|
repository-ref: main
|
||||||
|
repository-token: ${{ secrets.PAT }}
|
||||||
|
|
||||||
|
|
||||||
Cookiecutter openedx_devops deployment
|
Cookiecutter openedx_devops deployment
|
||||||
|
|
||||||
.. code-block:: shell
|
.. code-block:: shell
|
||||||
@ -136,9 +143,29 @@ WP Oauth Plugin Configuration
|
|||||||
This plugin enables your Open edX installation to authenticate against the WP Oauth plugin provider
|
This plugin enables your Open edX installation to authenticate against the WP Oauth plugin provider
|
||||||
in your Wordpress web site, configured as follows:
|
in your Wordpress web site, configured as follows:
|
||||||
|
|
||||||
.. image:: https://raw.githubusercontent.com/lpm0073/edx-oauth2-wordpress-backend/main/doc/wp-oauth-config.png
|
.. image:: https://raw.githubusercontent.com/lpm0073/wp-oauth-backend/main/doc/wp-oauth-config.png
|
||||||
:width: 100%
|
:width: 100%
|
||||||
:alt: WP OAuth Server configuration page
|
:alt: WP Oauth configuration page
|
||||||
|
|
||||||
|
Usage in Cookiecutter
|
||||||
|
---------------------
|
||||||
|
|
||||||
|
add a snippet of this form to openedx_devops/.github/workflows/build-openedx.yml
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
steps:
|
||||||
|
#------------------------------------------------------------------------
|
||||||
|
# ... add your initialization and any preceding steps ...
|
||||||
|
#------------------------------------------------------------------------
|
||||||
|
|
||||||
|
- name: Add the wp-oauth-backend
|
||||||
|
uses: openedx-actions/tutor-plugin-build-openedx-add-requirement@v1.0.0
|
||||||
|
with:
|
||||||
|
repository: wp-oauth-backend
|
||||||
|
repository-organization: lpm0073
|
||||||
|
repository-ref: v1.0.2
|
||||||
|
|
||||||
|
|
||||||
Sample lms log output
|
Sample lms log output
|
||||||
---------------------
|
---------------------
|
||||||
@ -147,13 +174,13 @@ Sample lms log output
|
|||||||
.. code-block:: shell
|
.. code-block:: shell
|
||||||
|
|
||||||
2022-10-06 20:17:08,832 INFO 19 [tracking] [user None] [ip 192.168.6.26] logger.py:41 - {"name": "/auth/login/stepwisemath-oauth/", "context": {"user_id": null, "path": "/auth/login/stepwisemath-oauth/", "course_id": "", "org_id": "", "enterprise_uuid": ""}, "username": "", "session": "a3f4ac2a5bf97f717f5745984059891b", "ip": "192.168.6.26", "agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36", "host": "web.stepwisemath.ai", "referer": "https://web.stepwisemath.ai/login", "accept_language": "en-US,en;q=0.9,es-MX;q=0.8,es-US;q=0.7,es;q=0.6", "event": "{\"GET\": {\"auth_entry\": [\"login\"], \"next\": [\"/dashboard\"]}, \"POST\": {}}", "time": "2022-10-06T20:17:08.832684+00:00", "event_type": "/auth/login/stepwisemath-oauth/", "event_source": "server", "page": null}
|
2022-10-06 20:17:08,832 INFO 19 [tracking] [user None] [ip 192.168.6.26] logger.py:41 - {"name": "/auth/login/stepwisemath-oauth/", "context": {"user_id": null, "path": "/auth/login/stepwisemath-oauth/", "course_id": "", "org_id": "", "enterprise_uuid": ""}, "username": "", "session": "a3f4ac2a5bf97f717f5745984059891b", "ip": "192.168.6.26", "agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36", "host": "web.stepwisemath.ai", "referer": "https://web.stepwisemath.ai/login", "accept_language": "en-US,en;q=0.9,es-MX;q=0.8,es-US;q=0.7,es;q=0.6", "event": "{\"GET\": {\"auth_entry\": [\"login\"], \"next\": [\"/dashboard\"]}, \"POST\": {}}", "time": "2022-10-06T20:17:08.832684+00:00", "event_type": "/auth/login/stepwisemath-oauth/", "event_source": "server", "page": null}
|
||||||
2022-10-06 20:17:09,230 INFO 19 [oauth2_wordpress.wp_oauth] [user None] [ip 192.168.6.26] wp_oauth.py:216 - AUTHORIZATION_URL: https://stepwisemath.ai/oauth/authorize
|
2022-10-06 20:17:09,230 INFO 19 [wp_oauth_backend.wp_oauth] [user None] [ip 192.168.6.26] wp_oauth.py:216 - AUTHORIZATION_URL: https://stepwisemath.ai/oauth/authorize
|
||||||
[pid: 19|app: 0|req: 2/19] 192.168.4.4 () {68 vars in 1889 bytes} [Thu Oct 6 20:17:08 2022] GET /auth/login/stepwisemath-oauth/?auth_entry=login&next=%2Fdashboard => generated 0 bytes in 430 msecs (HTTP/1.1 302) 9 headers in 922 bytes (1 switches on core 0)
|
[pid: 19|app: 0|req: 2/19] 192.168.4.4 () {68 vars in 1889 bytes} [Thu Oct 6 20:17:08 2022] GET /auth/login/stepwisemath-oauth/?auth_entry=login&next=%2Fdashboard => generated 0 bytes in 430 msecs (HTTP/1.1 302) 9 headers in 922 bytes (1 switches on core 0)
|
||||||
2022-10-06 20:17:38,485 INFO 7 [tracking] [user None] [ip 192.168.6.26] logger.py:41 - {"name": "/auth/complete/stepwisemath-oauth/", "context": {"user_id": null, "path": "/auth/complete/stepwisemath-oauth/", "course_id": "", "org_id": "", "enterprise_uuid": ""}, "username": "", "session": "a3f4ac2a5bf97f717f5745984059891b", "ip": "192.168.6.26", "agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36", "host": "web.stepwisemath.ai", "referer": "https://stepwisemath.ai/", "accept_language": "en-US,en;q=0.9,es-MX;q=0.8,es-US;q=0.7,es;q=0.6", "event": "{\"GET\": {\"redirect_state\": [\"pdbIKIcEbhjVr3Kon5VXUWWiy5kuX921\"], \"code\": [\"q0antmap4qfamd6pe24jh75pdprahpdiyitmut0o\"], \"state\": [\"pdbIKIcEbhjVr3Kon5VXUWWiy5kuX921\"], \"iframe\": [\"break\"]}, \"POST\": {}}", "time": "2022-10-06T20:17:38.484675+00:00", "event_type": "/auth/complete/stepwisemath-oauth/", "event_source": "server", "page": null}
|
2022-10-06 20:17:38,485 INFO 7 [tracking] [user None] [ip 192.168.6.26] logger.py:41 - {"name": "/auth/complete/stepwisemath-oauth/", "context": {"user_id": null, "path": "/auth/complete/stepwisemath-oauth/", "course_id": "", "org_id": "", "enterprise_uuid": ""}, "username": "", "session": "a3f4ac2a5bf97f717f5745984059891b", "ip": "192.168.6.26", "agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36", "host": "web.stepwisemath.ai", "referer": "https://stepwisemath.ai/", "accept_language": "en-US,en;q=0.9,es-MX;q=0.8,es-US;q=0.7,es;q=0.6", "event": "{\"GET\": {\"redirect_state\": [\"pdbIKIcEbhjVr3Kon5VXUWWiy5kuX921\"], \"code\": [\"q0antmap4qfamd6pe24jh75pdprahpdiyitmut0o\"], \"state\": [\"pdbIKIcEbhjVr3Kon5VXUWWiy5kuX921\"], \"iframe\": [\"break\"]}, \"POST\": {}}", "time": "2022-10-06T20:17:38.484675+00:00", "event_type": "/auth/complete/stepwisemath-oauth/", "event_source": "server", "page": null}
|
||||||
2022-10-06 20:17:38,496 INFO 7 [oauth2_wordpress.wp_oauth] [user None] [ip 192.168.6.26] wp_oauth.py:223 - ACCESS_TOKEN_URL: https://stepwisemath.ai/oauth/token
|
2022-10-06 20:17:38,496 INFO 7 [wp_oauth_backend.wp_oauth] [user None] [ip 192.168.6.26] wp_oauth.py:223 - ACCESS_TOKEN_URL: https://stepwisemath.ai/oauth/token
|
||||||
2022-10-06 20:17:40,197 INFO 7 [oauth2_wordpress.wp_oauth] [user None] [ip 192.168.6.26] wp_oauth.py:230 - USER_QUERY: https://stepwisemath.ai/oauth/me
|
2022-10-06 20:17:40,197 INFO 7 [wp_oauth_backend.wp_oauth] [user None] [ip 192.168.6.26] wp_oauth.py:230 - USER_QUERY: https://stepwisemath.ai/oauth/me
|
||||||
2022-10-06 20:17:40,197 INFO 7 [oauth2_wordpress.wp_oauth] [user None] [ip 192.168.6.26] wp_oauth.py:363 - user_data() url: https://stepwisemath.ai/oauth/me?access_token=jx2zql9fw2jx9s7tayik4ybfjrmuhb7m5csb1mtl
|
2022-10-06 20:17:40,197 INFO 7 [wp_oauth_backend.wp_oauth] [user None] [ip 192.168.6.26] wp_oauth.py:363 - user_data() url: https://stepwisemath.ai/oauth/me?access_token=jx2zql9fw2jx9s7tayik4ybfjrmuhb7m5csb1mtl
|
||||||
2022-10-06 20:17:41,965 INFO 7 [oauth2_wordpress.wp_oauth] [user None] [ip 192.168.6.26] wp_oauth.py:368 - user_data() response: {
|
2022-10-06 20:17:41,965 INFO 7 [wp_oauth_backend.wp_oauth] [user None] [ip 192.168.6.26] wp_oauth.py:368 - user_data() response: {
|
||||||
"ID": "7",
|
"ID": "7",
|
||||||
"display_name": "Test McBugster",
|
"display_name": "Test McBugster",
|
||||||
"user_email": "test@stepwisemath.ai",
|
"user_email": "test@stepwisemath.ai",
|
||||||
@ -165,7 +192,7 @@ Sample lms log output
|
|||||||
],
|
],
|
||||||
"user_status": "0"
|
"user_status": "0"
|
||||||
}
|
}
|
||||||
2022-10-06 20:17:41,966 INFO 7 [oauth2_wordpress.wp_oauth] [user None] [ip 192.168.6.26] wp_oauth.py:269 - get_user_details() received wp-oauth user data response json dict: {
|
2022-10-06 20:17:41,966 INFO 7 [wp_oauth_backend.wp_oauth] [user None] [ip 192.168.6.26] wp_oauth.py:269 - get_user_details() received wp-oauth user data response json dict: {
|
||||||
"ID": "7",
|
"ID": "7",
|
||||||
"display_name": "Test McBugster",
|
"display_name": "Test McBugster",
|
||||||
"user_email": "test@stepwisemath.ai",
|
"user_email": "test@stepwisemath.ai",
|
||||||
@ -177,8 +204,8 @@ Sample lms log output
|
|||||||
],
|
],
|
||||||
"user_status": "0"
|
"user_status": "0"
|
||||||
}
|
}
|
||||||
2022-10-06 20:17:41,966 INFO 7 [oauth2_wordpress.wp_oauth] [user None] [ip 192.168.6.26] wp_oauth.py:317 - get_user_details() processing response object
|
2022-10-06 20:17:41,966 INFO 7 [wp_oauth_backend.wp_oauth] [user None] [ip 192.168.6.26] wp_oauth.py:317 - get_user_details() processing response object
|
||||||
2022-10-06 20:17:41,966 INFO 7 [oauth2_wordpress.wp_oauth] [user None] [ip 192.168.6.26] wp_oauth.py:241 - user_details.setter: new value set {
|
2022-10-06 20:17:41,966 INFO 7 [wp_oauth_backend.wp_oauth] [user None] [ip 192.168.6.26] wp_oauth.py:241 - user_details.setter: new value set {
|
||||||
"date_joined": "2022-10-06 19:57:56",
|
"date_joined": "2022-10-06 19:57:56",
|
||||||
"email": "test@stepwisemath.ai",
|
"email": "test@stepwisemath.ai",
|
||||||
"first_name": "Test",
|
"first_name": "Test",
|
||||||
@ -193,7 +220,7 @@ Sample lms log output
|
|||||||
"user_status": "0",
|
"user_status": "0",
|
||||||
"username": "testaccount"
|
"username": "testaccount"
|
||||||
}
|
}
|
||||||
2022-10-06 20:17:41,967 INFO 7 [oauth2_wordpress.wp_oauth] [user None] [ip 192.168.6.26] wp_oauth.py:345 - get_user_details() returning: {
|
2022-10-06 20:17:41,967 INFO 7 [wp_oauth_backend.wp_oauth] [user None] [ip 192.168.6.26] wp_oauth.py:345 - get_user_details() returning: {
|
||||||
"date_joined": "2022-10-06 19:57:56",
|
"date_joined": "2022-10-06 19:57:56",
|
||||||
"email": "test@stepwisemath.ai",
|
"email": "test@stepwisemath.ai",
|
||||||
"first_name": "Test",
|
"first_name": "Test",
|
||||||
@ -208,7 +235,7 @@ Sample lms log output
|
|||||||
"user_status": "0",
|
"user_status": "0",
|
||||||
"username": "testaccount"
|
"username": "testaccount"
|
||||||
}
|
}
|
||||||
2022-10-06 20:17:41,972 INFO 7 [oauth2_wordpress.wp_oauth] [user None] [ip 192.168.6.26] wp_oauth.py:269 - get_user_details() received extended get_user_details() return dict: {
|
2022-10-06 20:17:41,972 INFO 7 [wp_oauth_backend.wp_oauth] [user None] [ip 192.168.6.26] wp_oauth.py:269 - get_user_details() received extended get_user_details() return dict: {
|
||||||
"access_token": "jx2zql9fw2jx9s7tayik4ybfjrmuhb7m5csb1mtl",
|
"access_token": "jx2zql9fw2jx9s7tayik4ybfjrmuhb7m5csb1mtl",
|
||||||
"date_joined": "2022-10-06 19:57:56",
|
"date_joined": "2022-10-06 19:57:56",
|
||||||
"email": "test@stepwisemath.ai",
|
"email": "test@stepwisemath.ai",
|
||||||
@ -225,7 +252,7 @@ Sample lms log output
|
|||||||
"user_status": "0",
|
"user_status": "0",
|
||||||
"username": "testaccount"
|
"username": "testaccount"
|
||||||
}
|
}
|
||||||
2022-10-06 20:17:41,973 INFO 7 [oauth2_wordpress.wp_oauth] [user None] [ip 192.168.6.26] wp_oauth.py:241 - user_details.setter: new value set {
|
2022-10-06 20:17:41,973 INFO 7 [wp_oauth_backend.wp_oauth] [user None] [ip 192.168.6.26] wp_oauth.py:241 - user_details.setter: new value set {
|
||||||
"access_token": "jx2zql9fw2jx9s7tayik4ybfjrmuhb7m5csb1mtl",
|
"access_token": "jx2zql9fw2jx9s7tayik4ybfjrmuhb7m5csb1mtl",
|
||||||
"date_joined": "2022-10-06 19:57:56",
|
"date_joined": "2022-10-06 19:57:56",
|
||||||
"email": "test@stepwisemath.ai",
|
"email": "test@stepwisemath.ai",
|
||||||
@ -242,7 +269,7 @@ Sample lms log output
|
|||||||
"user_status": "0",
|
"user_status": "0",
|
||||||
"username": "testaccount"
|
"username": "testaccount"
|
||||||
}
|
}
|
||||||
2022-10-06 20:17:41,973 INFO 7 [oauth2_wordpress.wp_oauth] [user None] [ip 192.168.6.26] wp_oauth.py:290 - get_user_details() returning extended get_user_details() return dict: {
|
2022-10-06 20:17:41,973 INFO 7 [wp_oauth_backend.wp_oauth] [user None] [ip 192.168.6.26] wp_oauth.py:290 - get_user_details() returning extended get_user_details() return dict: {
|
||||||
"access_token": "jx2zql9fw2jx9s7tayik4ybfjrmuhb7m5csb1mtl",
|
"access_token": "jx2zql9fw2jx9s7tayik4ybfjrmuhb7m5csb1mtl",
|
||||||
"date_joined": "2022-10-06 19:57:56",
|
"date_joined": "2022-10-06 19:57:56",
|
||||||
"email": "test@stepwisemath.ai",
|
"email": "test@stepwisemath.ai",
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 406 KiB |
@ -1 +0,0 @@
|
|||||||
__version__ = "1.0.8"
|
|
@ -3,12 +3,12 @@ requires = ["setuptools", "wheel"]
|
|||||||
build-backend = "setuptools.build_meta:__legacy__"
|
build-backend = "setuptools.build_meta:__legacy__"
|
||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "edx-oauth2-wordpress-backend"
|
name = "wp-oauth-backend_lpm0073"
|
||||||
version = "1.0.8"
|
version = "1.0.2"
|
||||||
authors = [
|
authors = [
|
||||||
{ name="Lawrence McDaniel", email="lpm0073@gmail.com" },
|
{ name="Lawrence McDaniel", email="lpm0073@gmail.com" },
|
||||||
]
|
]
|
||||||
description = "An Open edX Python Social Auth backend for Wordpress"
|
description = "A WP Oauth Python Social Auth backend for Open edX"
|
||||||
readme = "README.rst"
|
readme = "README.rst"
|
||||||
requires-python = ">=3.7"
|
requires-python = ">=3.7"
|
||||||
classifiers = [
|
classifiers = [
|
||||||
@ -17,11 +17,11 @@ classifiers = [
|
|||||||
"Operating System :: OS Independent",
|
"Operating System :: OS Independent",
|
||||||
]
|
]
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"social-auth-core==4.3.0",
|
"social-auth-core==4.2.0",
|
||||||
"social-auth-app-django==5.0.0"
|
"social-auth-app-django==5.0.0"
|
||||||
]
|
]
|
||||||
keywords = ["Open edX", "oauth", "Wordpress"]
|
keywords = ["Wordpress", "OAuth", "Open edX"]
|
||||||
|
|
||||||
[project.urls]
|
[project.urls]
|
||||||
"Homepage" = "https://github.com/lpm0073/edx-oauth2-wordpress-backend"
|
"Homepage" = "https://github.com/lpm0073/wp-oauth-backend"
|
||||||
"Bug Tracker" = "https://github.com/lpm0073/edx-oauth2-wordpress-backend/issues"
|
"Bug Tracker" = "https://github.com/lpm0073/wp-oauth-backend/issues"
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
# date: oct-2022
|
# date: oct-2022
|
||||||
#
|
#
|
||||||
# usage: a work in progress. build package and upload to PyPi.
|
# usage: a work in progress. build package and upload to PyPi.
|
||||||
# https://pypi.org/project/edx-oauth2-wordpress-backend/
|
# https://pypi.org/project/wp-oauth-backend/
|
||||||
# https://pypi.org/project/edx-oauth2-wordpress-backend-lpm0073/
|
# https://pypi.org/project/wp-oauth-backend-lpm0073/
|
||||||
#
|
#
|
||||||
# see: https://www.freecodecamp.org/news/how-to-create-and-upload-your-first-python-package-to-pypi/
|
# see: https://www.freecodecamp.org/news/how-to-create-and-upload-your-first-python-package-to-pypi/
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
@ -16,7 +16,8 @@ python -m pip install --upgrade build
|
|||||||
|
|
||||||
sudo rm -r build
|
sudo rm -r build
|
||||||
sudo rm -r dist
|
sudo rm -r dist
|
||||||
sudo rm -r edx_oauth2_wordpress_backend.egg-info
|
sudo rm -r wp_oauth_backend.egg-info
|
||||||
|
sudo rm -r wp_oauth_backend_lpm0073.egg-info
|
||||||
|
|
||||||
python3 -m build --sdist ./
|
python3 -m build --sdist ./
|
||||||
python3 -m build --wheel ./
|
python3 -m build --wheel ./
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
# Stable Python Social Auth, found in Open edX Olive
|
# Stable Python Social Auth, found in Open edX Nutmeg
|
||||||
social-auth-app-django>=5.0.0
|
social-auth-app-django==5.0.0
|
||||||
social-auth-core>=4.3.0
|
social-auth-core==4.2.0
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# Packages for testing
|
# Packages for testing
|
||||||
pytest>=7.1.1
|
pytest==7.1.1
|
||||||
httpretty>=1.1.4
|
httpretty==1.1.4
|
||||||
pycodestyle>=2.8.0
|
pycodestyle==2.8.0
|
||||||
-e .
|
-e .
|
||||||
|
12
setup.py
12
setup.py
@ -20,7 +20,7 @@ def load_readme():
|
|||||||
def load_about():
|
def load_about():
|
||||||
about = {}
|
about = {}
|
||||||
with io.open(
|
with io.open(
|
||||||
os.path.join(HERE, "oauth2_wordpress", "__about__.py"),
|
os.path.join(HERE, "wp_oauth_backend", "__about__.py"),
|
||||||
"rt",
|
"rt",
|
||||||
encoding="utf-8",
|
encoding="utf-8",
|
||||||
) as f:
|
) as f:
|
||||||
@ -65,7 +65,7 @@ ABOUT = load_about()
|
|||||||
VERSION = ABOUT["__version__"]
|
VERSION = ABOUT["__version__"]
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="edx-oauth2-wordpress-backend",
|
name="wp-oauth-backend",
|
||||||
version=VERSION,
|
version=VERSION,
|
||||||
description=(
|
description=(
|
||||||
"An OAuth backend for the WP OAuth Wordpress Plugin, "
|
"An OAuth backend for the WP OAuth Wordpress Plugin, "
|
||||||
@ -74,15 +74,17 @@ setup(
|
|||||||
long_description=README,
|
long_description=README,
|
||||||
author="Lawrence McDaniel, lpm0073@gmail.com",
|
author="Lawrence McDaniel, lpm0073@gmail.com",
|
||||||
author_email="lpm0073@gmail.com",
|
author_email="lpm0073@gmail.com",
|
||||||
url="https://git.unecon.ru/gevorkyan.aa/edx-oauth2-wordpress-backend",
|
url="https://github.com/StepwiseMath/wp-oauth-backend",
|
||||||
project_urls={
|
project_urls={
|
||||||
"Code": "https://git.unecon.ru/gevorkyan.aa/edx-oauth2-wordpress-backend"
|
"Code": "https://github.com/StepwiseMath/wp-oauth-backend",
|
||||||
|
"Issue tracker": "https://github.com/StepwiseMath/wp-oauth-backend/issues",
|
||||||
|
"Community": "https://stepwisemath.ai",
|
||||||
},
|
},
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
package_data={"": ["*.html"]}, # include any templates found in this repo.
|
package_data={"": ["*.html"]}, # include any templates found in this repo.
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
keywords="Open edX, oauth, Wordpress",
|
keywords="Wordpress, oauth, Open edX",
|
||||||
python_requires=">=3.7",
|
python_requires=">=3.7",
|
||||||
install_requires=load_requirements("requirements/stable-psa.txt"),
|
install_requires=load_requirements("requirements/stable-psa.txt"),
|
||||||
classifiers=[
|
classifiers=[
|
||||||
|
1
wp_oauth_backend/__about__.py
Normal file
1
wp_oauth_backend/__about__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
__version__ = "1.0.2"
|
@ -4,20 +4,23 @@ written by: Lawrence McDaniel
|
|||||||
|
|
||||||
date: oct-2022
|
date: oct-2022
|
||||||
|
|
||||||
|
usage: subclass of BaseOAuth2 Third Party Authtencation client to
|
||||||
|
handle the field mapping and data conversions between
|
||||||
|
the dict that WP Oauth returns versus the dict that Open edX
|
||||||
|
actually needs.
|
||||||
"""
|
"""
|
||||||
import json
|
import json
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
from urllib.request import urlopen
|
from urllib.request import urlopen
|
||||||
from urllib.parse import urljoin
|
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
from social_core.backends.oauth import BaseOAuth2
|
from social_core.backends.oauth import BaseOAuth2
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.conf import settings
|
|
||||||
|
|
||||||
User = get_user_model()
|
User = get_user_model()
|
||||||
logger = getLogger(__name__)
|
logger = getLogger(__name__)
|
||||||
|
|
||||||
VERBOSE_LOGGING = False
|
VERBOSE_LOGGING = True
|
||||||
|
|
||||||
|
|
||||||
class WPOpenEdxOAuth2(BaseOAuth2):
|
class WPOpenEdxOAuth2(BaseOAuth2):
|
||||||
@ -46,20 +49,11 @@ class WPOpenEdxOAuth2(BaseOAuth2):
|
|||||||
# Third Party Authentication / Provider Configuration (OAuth)
|
# Third Party Authentication / Provider Configuration (OAuth)
|
||||||
# setup page drop-down box titled, "Backend name:", just above
|
# setup page drop-down box titled, "Backend name:", just above
|
||||||
# the "Client ID:" and "Client Secret:" fields.
|
# the "Client ID:" and "Client Secret:" fields.
|
||||||
|
|
||||||
name = "wp-oauth"
|
name = "wp-oauth"
|
||||||
|
|
||||||
# note: no slash at the end of the base url. Python Social Auth
|
# note: no slash at the end of the base url. Python Social Auth
|
||||||
# might clean this up for you, but i'm not 100% certain of that.
|
# might clean this up for you, but i'm not 100% certain of that.
|
||||||
BASE_URL = settings.FEATURES.get('WP_PROVIDER_URL')
|
BASE_URL = "https://set-me-please.com"
|
||||||
|
|
||||||
# a path to append to the BASE_URL: https://oauth_host.com/oauth/
|
|
||||||
PATH = "oauth/"
|
|
||||||
|
|
||||||
# endpoint defaults
|
|
||||||
AUTHORIZATION_ENDPOINT = "authorize"
|
|
||||||
TOKEN_ENDPOINT = "token"
|
|
||||||
USERINFO_ENDPOINT = "me"
|
|
||||||
|
|
||||||
# The default key name where the user identification field is defined, it’s
|
# The default key name where the user identification field is defined, it’s
|
||||||
# used in the auth process when some basic user data is returned. This Id
|
# used in the auth process when some basic user data is returned. This Id
|
||||||
@ -108,9 +102,6 @@ class WPOpenEdxOAuth2(BaseOAuth2):
|
|||||||
# list can be delimited with commas, spaces, whatever.
|
# list can be delimited with commas, spaces, whatever.
|
||||||
SCOPE_SEPARATOR = " "
|
SCOPE_SEPARATOR = " "
|
||||||
|
|
||||||
# Enable updates on the Django user object on successful WordPress login.
|
|
||||||
UPDATE_USER_ON_LOGIN = True
|
|
||||||
|
|
||||||
# private utility function. not part of psa.
|
# private utility function. not part of psa.
|
||||||
def _urlopen(self, url):
|
def _urlopen(self, url):
|
||||||
"""
|
"""
|
||||||
@ -213,10 +204,6 @@ class WPOpenEdxOAuth2(BaseOAuth2):
|
|||||||
return "get_user_details() return dict"
|
return "get_user_details() return dict"
|
||||||
return "unrecognized response dict"
|
return "unrecognized response dict"
|
||||||
|
|
||||||
@property
|
|
||||||
def URL(self):
|
|
||||||
return urljoin(self.BASE_URL, self.PATH)
|
|
||||||
|
|
||||||
# override Python Social Auth default end points.
|
# override Python Social Auth default end points.
|
||||||
# see https://wp-oauth.com/docs/general/endpoints/
|
# see https://wp-oauth.com/docs/general/endpoints/
|
||||||
#
|
#
|
||||||
@ -224,21 +211,21 @@ class WPOpenEdxOAuth2(BaseOAuth2):
|
|||||||
# so that we can include logging for diagnostic purposes.
|
# so that we can include logging for diagnostic purposes.
|
||||||
@property
|
@property
|
||||||
def AUTHORIZATION_URL(self) -> str:
|
def AUTHORIZATION_URL(self) -> str:
|
||||||
url = urljoin(self.URL, self.AUTHORIZATION_ENDPOINT)
|
url = f"{self.BASE_URL}/oauth/authorize"
|
||||||
if VERBOSE_LOGGING:
|
if VERBOSE_LOGGING:
|
||||||
logger.info("AUTHORIZATION_URL: {url}".format(url=url))
|
logger.info("AUTHORIZATION_URL: {url}".format(url=url))
|
||||||
return url
|
return url
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def ACCESS_TOKEN_URL(self) -> str:
|
def ACCESS_TOKEN_URL(self) -> str:
|
||||||
url = urljoin(self.URL, self.TOKEN_ENDPOINT)
|
url = f"{self.BASE_URL}/oauth/token"
|
||||||
if VERBOSE_LOGGING:
|
if VERBOSE_LOGGING:
|
||||||
logger.info("ACCESS_TOKEN_URL: {url}".format(url=url))
|
logger.info("ACCESS_TOKEN_URL: {url}".format(url=url))
|
||||||
return url
|
return url
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def USER_QUERY(self) -> str:
|
def USER_QUERY(self) -> str:
|
||||||
url = urljoin(self.URL, self.USERINFO_ENDPOINT)
|
url = f"{self.BASE_URL}/oauth/me"
|
||||||
if VERBOSE_LOGGING:
|
if VERBOSE_LOGGING:
|
||||||
logger.info("USER_QUERY: {url}".format(url=url))
|
logger.info("USER_QUERY: {url}".format(url=url))
|
||||||
return url
|
return url
|
||||||
@ -409,7 +396,6 @@ class WPOpenEdxOAuth2(BaseOAuth2):
|
|||||||
except User.DoesNotExist:
|
except User.DoesNotExist:
|
||||||
return self.user_details
|
return self.user_details
|
||||||
|
|
||||||
if self.UPDATE_USER_ON_LOGIN:
|
|
||||||
if (user.is_superuser != self.user_details["is_superuser"]) or (
|
if (user.is_superuser != self.user_details["is_superuser"]) or (
|
||||||
user.is_staff != self.user_details["is_staff"]
|
user.is_staff != self.user_details["is_staff"]
|
||||||
):
|
):
|
||||||
@ -421,6 +407,7 @@ class WPOpenEdxOAuth2(BaseOAuth2):
|
|||||||
username=user.username
|
username=user.username
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
if (user.first_name != self.user_details["first_name"]) or (
|
if (user.first_name != self.user_details["first_name"]) or (
|
||||||
user.last_name != self.user_details["last_name"]
|
user.last_name != self.user_details["last_name"]
|
||||||
):
|
):
|
Loading…
x
Reference in New Issue
Block a user