Last active
November 8, 2017 16:05
-
-
Save clintonb/f0080031ec444f04f3d2f0b3460d1905 to your computer and use it in GitHub Desktop.
Test JWTs with the edX Discovery Service
This file contains hidden or 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 script tests the retrieval of a JWT access token and submission of the token to the Discovery Service. If all goes | |
well, you should see a print out of the token and data from the Discovery API's courses endpoint. | |
NOTE: You will need to install the edx-rest-api-client package at https://pypi.python.org/pypi/edx-rest-api-client. | |
""" | |
from edx_rest_api_client.client import EdxRestApiClient | |
# TODO Set these values to the URLs of your own services | |
ACCESS_TOKEN_URL = 'https://courses.example.com/oauth2/access_token' | |
DISCOVERY_URL = 'https://discovery.example.com/api/v1/' | |
# TODO These values should come from your OAuth provider (LMS). | |
OAUTH_CLIENT_ID = '' | |
OAUTH_CLIENT_SECRET = '' | |
# Retrieve JWT access token | |
access_token, expires = EdxRestApiClient.get_oauth_access_token(ACCESS_TOKEN_URL, OAUTH_CLIENT_ID, OAUTH_CLIENT_SECRET, | |
token_type='jwt') | |
print('Access Token') | |
print('Expires: %s', expires) | |
print('JWT: %s', access_token) | |
client = EdxRestApiClient(DISCOVERY_URL, jwt=access_token) | |
print(client.courses.get()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment