Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions docs/examples/wso2.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
WSO2 OAuth 2 Tutorial
==========================

Setup subscriptions following the instructions on your WSO2 gateway. When you
have obtained a ``client_id`` and a ``client_secret`` you can try out the
command line interactive example below.


.. code-block:: pycon

>>> from requests.auth import HTTPBasicAuth
>>> from oauthlib.oauth2 import BackendApplicationClient
>>> from requests_oauthlib import OAuth2Session

>>> #grab client_id and client_secret:
>>> client_id = u'<clientid>'
>>> client_secret = u'<secret>'
>>> token_url = 'https://wso2gateway.myorg.org/token'

>>> #generate HTTPBasicAuth Header
>>> basic_auth = HTTPBasicAuth(client_id, client_secret)
>>> client = BackendApplicationClient(client_id=client_id)

>>> #start oauth session
>>> oauth = OAuth2Session(client=client)
>>> token = oauth.fetch_token(token_url=token_url,
auth=basic_auth)

>>> r = oauth.get(u'https://wso2gateway.myorg.org/api/v1/api',
>>> headers={'Accept':'application/json'})
>>> print(r.json())
30 changes: 20 additions & 10 deletions docs/oauth2_workflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -141,22 +141,32 @@ The steps below outline how to use the Resource Owner Client Credentials Grant T
0. Obtain credentials from your OAuth provider. At minimum you will
need a ``client_id`` and ``client_secret``.

.. code-block:: pycon

>>> client_id = 'your_client_id'
>>> client_secret = 'your_client_secret'
.. code-block:: pycon
>>> client_id = 'your_client_id'
>>> client_secret = 'your_client_secret'

1. Fetch an access token from the provider.

.. code-block:: pycon
.. code-block:: pycon

>>> from oauthlib.oauth2 import BackendApplicationClient
>>> client = BackendApplicationClient(client_id=client_id)
>>> oauth = OAuth2Session(client=client)
>>> token = oauth.fetch_token(token_url='https://provider.com/oauth2/token', client_id=client_id,
client_secret=client_secret)
>>> from oauthlib.oauth2 import BackendApplicationClient
>>> client = BackendApplicationClient(client_id=client_id)
>>> oauth = OAuth2Session(client=client)
>>> token = oauth.fetch_token(token_url='https://provider.com/oauth2/token', client_id=client_id,
client_secret=client_secret)

If your provider requires that you pass auth credentials in a Basic Auth header, you can do this instead:

.. code-block:: pycon

>>> from oauthlib.oauth2 import BackendApplicationClient
>>> from requests.auth import HTTPBasicAuth
>>> auth = HTTPBasicAuth(client_id, client_secret)
>>> client = BackendApplicationClient(client_id=client_id)
>>> oauth = OAuth2Session(client=client)
>>> token = oauth.fetch_token(token_url='https://provider.com/oauth2/token', auth=auth)

Refreshing tokens
-----------------

Expand Down