diff --git a/docs/index.rst b/docs/index.rst index f8f8692..953c226 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -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:: @@ -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 diff --git a/flask_oidc/__init__.py b/flask_oidc/__init__.py index 5ca54a4..46be703 100644 --- a/flask_oidc/__init__.py +++ b/flask_oidc/__init__.py @@ -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')