Wordpress Oauth2 Backend for Open edX

Hello all, i created this edx-oauth2-wordpress-backend that will enable oauth2 third party authentication via any Wordpress site using the wp-oauth Wordpress plugin. There are thorough “getting started” instructions in the README.

If you are already using an open edx plugin in your installation then you can simply add a Python module with your subclass definition. Here’s an example: https://github.com/StepwiseMath/stepwise-edx-plugin. You can create your own custom Wordpress oauth2 backend with only 4 lines of code!

from wp_oauth_backend.wp_oauth import WPOpenEdxOAuth2

class StepwiseMathWPOAuth2(WPOpenEdxOAuth2):
    # This is the string value that will appear in the LMS Django Admin
    # Third Party Authentication / Provider Configuration (OAuth)
    # setup page drop-down box titled, "Backend name:", just above
    # the "Client ID:" and "Client Secret:" fields.
    name = "stepwisemath-oauth"
    BASE_URL = "https://stepwisemath.ai"

This backend generates verbose, informative lms log entries which are intended to eliminate some of the pain that customarily comes with setting up oauth2 third party authentication. Example lms log data:

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 [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 [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 [wp_oauth_backend.wp_oauth] [user None] [ip 192.168.6.26] wp_oauth.py:368 - user_data() response: {
    "ID": "7",
   "display_name": "Test McBugster",
    "user_email": "test@stepwisemath.ai",
    "user_login": "testaccount",
    "user_nicename": "testaccount",
    "user_registered": "2022-10-06 19:57:56",
    "user_roles": [
        "administrator"
    ],
    "user_status": "0"
}
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",
   "display_name": "Test McBugster",
    "user_email": "test@stepwisemath.ai",
    "user_login": "testaccount",
    "user_nicename": "testaccount",
    "user_registered": "2022-10-06 19:57:56",
    "user_roles": [
        "administrator"
    ],
    "user_status": "0"
}
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 [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",
    "email": "test@stepwisemath.ai",
    "first_name": "Test",
    "fullname": "Test McBugster",
    "id": 7,
    "is_staff": true,
    "is_superuser": true,
    "last_name": "McBugster",
    "refresh_token": "",
    "scope": "",
    "token_type": "",
    "user_status": "0",
    "username": "testaccount"
}
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",
    "email": "test@stepwisemath.ai",
    "first_name": "Test",
    "fullname": "Test McBugster",
    "id": 7,
    "is_staff": true,
    "is_superuser": true,
    "last_name": "McBugster",
    "refresh_token": "",
    "scope": "",
    "token_type": "",
    "user_status": "0",
    "username": "testaccount"
}
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",
    "date_joined": "2022-10-06 19:57:56",
    "email": "test@stepwisemath.ai",
    "expires_in": 3600,
    "first_name": "Test",
    "fullname": "Test McBugster",
    "id": 7,
    "is_staff": true,
    "is_superuser": true,
    "last_name": "McBugster",
    "refresh_token": "",
    "scope": "",
    "token_type": "",
    "user_status": "0",
    "username": "testaccount"
}
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",
    "date_joined": "2022-10-06 19:57:56",
    "email": "test@stepwisemath.ai",
    "expires_in": 3600,
    "first_name": "Test",
    "fullname": "Test McBugster",
    "id": 7,
    "is_staff": true,
    "is_superuser": true,
    "last_name": "McBugster",
    "refresh_token": "",
    "scope": "",
    "token_type": "",
    "user_status": "0",
    "username": "testaccount"
}
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",
    "date_joined": "2022-10-06 19:57:56",
    "email": "test@stepwisemath.ai",
    "expires_in": 3600,
    "first_name": "Test",
    "fullname": "Test McBugster",
    "id": 7,
    "is_staff": true,
    "is_superuser": true,
    "last_name": "McBugster",
    "refresh_token": "",
    "scope": "",
    "token_type": "",
    "user_status": "0",
    "username": "testaccount"
}
4 Likes