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

Added support for different response modes #41

Open
wants to merge 2 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
15 changes: 11 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def start_code_flow():
scopes, request.args.get("forceConsent", False),
request.args.get("allowConsentOptionDeselection", False),
request.args.get("responseType", "code"),
_config.get("response_mode", "query"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to leave the decision about the response mode to the client. You changed the backend so that it will work with both modes, which is good. Now the client could decide which mode to use:

request.args.get("response_mode", "query"),

The response_mode could be then removed from the settings.

request.args.get("ui_locales"),
request.args.get("max_age"),
request.args.get("claims"),
Expand Down Expand Up @@ -301,26 +302,32 @@ def ajax_callback():
return "ok"


@_app.route('/callback')
@_app.route('/callback', methods=["GET", "POST"])
def oauth_callback():
"""
Called when the resource owner is returning from the authorization server
:return:redirect to / with user info stored in the session.
"""

if request.method == "GET":
params = request.args
else:
params = request.form

if session.get("flow", None) != "code":
# This is the callback for a hybrid or implicit flow
return render_template('index.html')

if 'state' not in session or session['state'].decode() != request.args['state']:
if 'state' not in session or session['state'].decode() != params['state']:
return create_error('Missing or invalid state')

if "code_verifier" not in session:
return create_error("No code_verifier in session")

if 'code' not in request.args:
if 'code' not in params:
return create_error('No code in response')

user = callback(request.args)
user = callback(params)

session['session_id'] = generate_random_string()
_session_store[session['session_id']] = user
Expand Down
3 changes: 2 additions & 1 deletion client.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def refresh(self, refresh_token):
return json.loads(token_response.read())

def get_authn_req_url(self, session, acr, forceAuthN, scope, forceConsent, allowConsentOptionDeselection,
response_type, ui_locales, max_age, claims, send_parameters_via):
response_type, response_mode, ui_locales, max_age, claims, send_parameters_via):
"""
:param session: the session, will be used to keep the OAuth state
:param acr: The acr to request
Expand All @@ -199,6 +199,7 @@ def get_authn_req_url(self, session, acr, forceAuthN, scope, forceConsent, allow

request_args = {'scope': scope,
'response_type': response_type,
'response_mode': response_mode,
'client_id': self.config['client_id'],
'state': state,
'code_challenge': code_challenge,
Expand Down
1 change: 1 addition & 0 deletions settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"debug": true,
"scope": "openid profile email address phone",
"send_parameters_via": "query",
"response_mode": "query",
"client_id": "python-client",
"client_secret": "Password1",
"redirect_uri": "https://localhost:5443/callback",
Expand Down