add URL property and class variables for PATH and endpoint values. switch to urljoin()

This commit is contained in:
lpm0073 2022-11-08 18:40:24 -06:00
parent 49fa25f925
commit 249f776d64
7 changed files with 72 additions and 46 deletions

9
CHANGELOG.md Normal file
View File

@ -0,0 +1,9 @@
# CHANGE LOG
## Version 1.0.1 (2022-11-08)
- add property for URL
- add class variables for PATH, AUTHORIZATION_ENDPOINT, TOKEN_ENDPOINT, USERINFO_ENDPOINT
- switch to urllib.parse urljoin()
- add a Makefile
- change documentation to reference Wordpress miniOrange OAuth / OpenID Connect Server

40
Makefile Normal file
View File

@ -0,0 +1,40 @@
# -------------------------------------------------------------------------
# build a package for PyPi
# -------------------------------------------------------------------------
.PHONY: build
.PHONY: requirements
report:
cloc $(git ls-files)
build:
python3 -m pip install --upgrade setuptools wheel twine
python -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/*

View File

@ -22,7 +22,7 @@ Open edX OAuth2 Backend for Wordpress
Overview
--------
An Open edX oauth2 backend for `Wordpress <https://wordpress.org//>`_ `WP OAuth <https://wp-oauth.com/>`_.
An Open edX oauth2 backend for `Wordpress <https://wordpress.org//>`_ `miniOrange OAuth / OpenID Connect Server <https://www.miniorange.com/>`_.
- `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/>`_
@ -93,9 +93,9 @@ add these settings to django.conf:
* - WPOAUTH_BACKEND_BASE_URL
- https://stepwisemath.ai
* - WPOAUTH_BACKEND_CLIENT_ID
- see: https://stepwisemath.ai/wp-admin/admin.php?page=wo_manage_clients
- see: https://stepwisemath.ai/wp-admin/admin.php?page=mo_oauth_server_settings
* - WPOAUTH_BACKEND_CLIENT_SECRET
- see: https://stepwisemath.ai/wp-admin/admin.php?page=wo_manage_clients
- see: https://stepwisemath.ai/wp-admin/admin.php?page=mo_oauth_server_settings
* - SCOPE
- basic email profile
* - GRANT_TYPE
@ -115,22 +115,6 @@ add these settings to django.conf:
:alt: Open edX Django Admin Add Provider Configuration (OAuth)
5. Optional: Configure your devops
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Cookiecutter openedx_devops build
.. code-block:: shell
- name: Add the edx-oauth2-wordpress-backend
uses: openedx-actions/tutor-plugin-build-openedx-add-requirement@v1.0.0
with:
repository: edx-oauth2-wordpress-backend
repository-organization: StepwiseMath
repository-ref: main
repository-token: ${{ secrets.PAT }}
Cookiecutter openedx_devops deployment
.. code-block:: shell
@ -145,29 +129,9 @@ WP Oauth Plugin Configuration
This plugin enables your Open edX installation to authenticate against the WP Oauth plugin provider
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/edx-oauth2-wordpress-backend/main/doc/miniorange-oauth-config.png
:width: 100%
: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 edx-oauth2-wordpress-backend
uses: openedx-actions/tutor-plugin-build-openedx-add-requirement@v1.0.0
with:
repository: edx-oauth2-wordpress-backend
repository-organization: lpm0073
repository-ref: v1.0.0
:alt: miniOrange OAuth configuration page
Sample lms log output
---------------------

Binary file not shown.

After

Width:  |  Height:  |  Size: 406 KiB

View File

@ -1 +1 @@
__version__ = "1.0.0"
__version__ = "1.0.1"

View File

@ -12,6 +12,7 @@ usage: subclass of BaseOAuth2 Third Party Authtencation client to
import json
from urllib.parse import urlencode
from urllib.request import urlopen
from urllib.parse import urljoin
from logging import getLogger
from social_core.backends.oauth import BaseOAuth2
from django.contrib.auth import get_user_model
@ -55,6 +56,14 @@ class WPOpenEdxOAuth2(BaseOAuth2):
# might clean this up for you, but i'm not 100% certain of that.
BASE_URL = "https://set-me-please.com"
# a path to append to the BASE_URL: https://oauth_host.com/oauth/
PATH = "wp-json/moserver"
# endpoint defaults
AUTHORIZATION_ENDPOINT = "authorize"
TOKEN_ENDPOINT = "token"
USERINFO_ENDPOINT = "resource"
# The default key name where the user identification field is defined, its
# used in the auth process when some basic user data is returned. This Id
# is stored in the UserSocialAuth.uid field and this, together with the
@ -204,6 +213,10 @@ class WPOpenEdxOAuth2(BaseOAuth2):
return "get_user_details() return dict"
return "unrecognized response dict"
@property
def URL(self):
return urljoin(self.BASE_URL, self.PATH)
# override Python Social Auth default end points.
# see https://wp-oauth.com/docs/general/endpoints/
#
@ -211,21 +224,21 @@ class WPOpenEdxOAuth2(BaseOAuth2):
# so that we can include logging for diagnostic purposes.
@property
def AUTHORIZATION_URL(self) -> str:
url = f"{self.BASE_URL}/oauth/authorize"
url = urljoin(self.URL, self.AUTHORIZATION_ENDPOINT)
if VERBOSE_LOGGING:
logger.info("AUTHORIZATION_URL: {url}".format(url=url))
return url
@property
def ACCESS_TOKEN_URL(self) -> str:
url = f"{self.BASE_URL}/oauth/token"
url = urljoin(self.URL, self.TOKEN_ENDPOINT)
if VERBOSE_LOGGING:
logger.info("ACCESS_TOKEN_URL: {url}".format(url=url))
return url
@property
def USER_QUERY(self) -> str:
url = f"{self.BASE_URL}/oauth/me"
url = urljoin(self.URL, self.USERINFO_ENDPOINT)
if VERBOSE_LOGGING:
logger.info("USER_QUERY: {url}".format(url=url))
return url

View File

@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta:__legacy__"
[project]
name = "edx-oauth2-wordpress-backend"
version = "1.0.0"
version = "1.0.1"
authors = [
{ name="Lawrence McDaniel", email="lpm0073@gmail.com" },
]