diff --git a/docs/examples/wso2.rst b/docs/examples/wso2.rst new file mode 100644 index 00000000..6c36d09c --- /dev/null +++ b/docs/examples/wso2.rst @@ -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'' + >>> client_secret = u'' + >>> 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()) diff --git a/docs/oauth2_workflow.rst b/docs/oauth2_workflow.rst index eba0c68c..588480ec 100644 --- a/docs/oauth2_workflow.rst +++ b/docs/oauth2_workflow.rst @@ -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 -----------------