Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature custom callback without custom state #93

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ To do this, add the decorator `oidc.custom_callback` to your callback function.
This will get the (json-serializable) custom state that you passed in as
`customstate` to `oidc.redirect_to_auth_server`.
Note that to use this, you will need to set `OVERWRITE_REDIRECT_URI`.
Use parameter `custom` if you want to use custom state, `destination` if you
want to keep default state settings.

Example::

Expand All @@ -99,7 +101,7 @@ Example::
return oidc.redirect_to_auth_server(None, flask.request.values)

@app.route('/custom_callback')
@oidc.custom_callback
@oidc.custom_callback('custom')
def callback(data):
return 'Hello. You submitted %s' % data

Expand Down
32 changes: 17 additions & 15 deletions flask_oidc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,21 +666,23 @@ def _is_id_token_valid(self, id_token):

WRONG_GOOGLE_APPS_DOMAIN = 'WRONG_GOOGLE_APPS_DOMAIN'

def custom_callback(self, view_func):
"""
Wrapper function to use a custom callback.
The custom OIDC callback will get the custom state field passed in with
redirect_to_auth_server.
"""
@wraps(view_func)
def decorated(*args, **kwargs):
plainreturn, data = self._process_callback('custom')
if plainreturn:
return data
else:
return view_func(data, *args, **kwargs)
self._custom_callback = decorated
return decorated
def custom_callback(self, statefield='custom'):
def _custom_callback(view_func):
"""
Wrapper function to use a custom callback.
The custom OIDC callback will get the custom state field passed in with
redirect_to_auth_server.
"""
@wraps(view_func)
def decorated(*args, **kwargs):
plainreturn, data = self._process_callback(statefield)
if plainreturn:
return data
else:
return view_func(data, *args, **kwargs)
self._custom_callback = decorated
return decorated
return _custom_callback

def _oidc_callback(self):
plainreturn, data = self._process_callback('destination')
Expand Down