How to create an OAuth user in devstack

If you want to test your API endpoint using OAuth credentials and need to create a user in your devstack to do so, follow these steps.

Step-by-step guide

  1. Log into your devstack (if using vagrant)

  2. Inside vagrant, or using docker exec, create an oauth client for the staff user:

    $ bash -c 'python /edx/app/edxapp/edx-platform/ lms --settings=devstack create_oauth2_client "http://localhost:$2" "http://localhost:$2/complete/edx-oidc/" public --client_name $1 --client_id "$1-key" --client_secret "$1-secret" --trusted --logout_uri "http://localhost:$2/logout/" --username staff' -- "test" "8000"

    (where 8000 corresponds to the port that the LMS is running on locally)

  3. From anywhere (inside or outside devstack), get the access token (again assuming 8000 is your LMS port)

    $ curl -X POST -d "client_id=test-key&grant_type=password&username=staff&password=edx" http://localhost:8000/oauth2/access_token/
    {"access_token": "d6592ef055b124c04d91afdcad4f5ea580b1bbf9", "token_type": "Bearer", "expires_in": 2591999, "scope": ""}
  4. Use the access token 

    $ curl -H "Authorization: Bearer INSERT_EDX_ISSUED_ACCESS_TOKEN" http://localhost:8000/api/..