Skip to content

Commit

Permalink
Fix documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
lepture committed May 18, 2020
1 parent cad5bb4 commit 497f823
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/client/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ example, you want to use ``requests`` OAuth clients::

For instance, you want to use ``httpx`` OAuth clients::

$ pip install Authlib httpx==0.12.0
$ pip install -U Authlib httpx

Here is a simple overview of Flask OAuth client::

Expand Down
24 changes: 16 additions & 8 deletions docs/client/oauth2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -300,24 +300,32 @@ hooks are provided to solve those problems:
* ``refresh_token_response``: invoked before refresh token parsing.
* ``protected_request``: invoked before making a request.

For instance, linkedin is using a ``oauth2_access_token`` parameter in query
string to protect users' resources, let's fix it::
For instance, Stackoverflow MUST add a `site` parameter in query
string to protect users' resources. And stackoverflow's response is
not in JSON. Let's fix it::

from authlib.common.urls import add_params_to_uri
from authlib.common.urls import add_params_to_uri, url_decode

def _non_compliant_param_name(url, headers, data):
access_token = session.token.get('access_token')
token = [('oauth2_access_token', access_token)]
url = add_params_to_uri(url, token)
return url, headers, data
params = {'site': 'stackoverflow'}
url = add_params_to_uri(url, params)
return url, headers, body

def _fix_token_response(resp):
data = dict(url_decode(resp.text))
data['token_type'] = 'Bearer'
data['expires_in'] = int(data['expires'])
resp.json = lambda: data
return resp

session.register_compliance_hook(
'protected_request', _non_compliant_param_name)
session.register_compliance_hook(
'access_token_response', _fix_token_response)

If you find a non standard OAuth 2 services, and you can't fix it. Please
report it in GitHub issues.


.. _oidc_session:

OAuth 2 OpenID Connect
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ deps =
py27: unittest2
flask: Flask
flask: Flask-SQLAlchemy
async: httpx==0.12.0
async: httpx
async: pytest-asyncio
async: starlette
async: itsdangerous
Expand Down

0 comments on commit 497f823

Please sign in to comment.