elliotpeele / pyramid_oauth2_provider

An Oauth2 provider built on pyramid
MIT License
31 stars 16 forks source link

pyramid_oauth2_provider README

Warning:

You will need to reset your DB tables related to this library and provide a new ini config 'oauth2_provider.salt' when upgrading from v0.2.0. To reset the tables, run the init script with added boolean argument to drop:

initialize_pyramid_oauth2_provider_db-script.py development.ini true

Additionally, scrypt requires OpenSSL v1.1.0 or newer.

Getting Started

In an existing pyramid project you can take advantage of pyramid_oauth2_provider by doing the following:

Request Flow

Let's start by laying out a few ground rules when it comes to oauth2:

  1. All requests must be made via HTTPS.
  2. All data is transferred in headers and the body of messages rather than through url parameters.

The token endpoint is provided as a way to obtain and renew access_tokens.

Example initial token request:

    POST /oauth2/token HTTP/1.1
    Host: server.example.com
    Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW
    Content-Type: application/x-www-form-urlencoded

    grant_type=password&username=johndoe&password=A3ddj3w

Example refresh token request:

    POST /token HTTP/1.1
    Host: server.example.com
    Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW
    Content-Type: application/x-www-form-urlencoded

    grant_type=refresh_token&refresh_token=tGzv3JOkF0XG5Qx2TlKW&user_id=1234

Example token response:

    HTTP/1.1 200 OK
    Content-Type: application/json;charset=UTF-8
    Cache-Control: no-store
    Pragma: no-cache

    {
      "access_token":"2YotnFZFEjr1zCsicMWpAA",
      "token_type":"bearer",
      "expires_in":3600,
      "refresh_token":"tGzv3JOkF0XG5Qx2TlKW",
      "user_id":1234,
    }