Skip to content

Commit c8636f8

Browse files
authored
Merge pull request authlib#66 from Fisherworks/auth_when_owner_not_login
client ask for Auth on behalf of owner when owner got no session on auth server
2 parents ec0304d + 26e1a60 commit c8636f8

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*.sqlite
22
*.pyc
3+
venv/*

website/routes.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import time
2-
from flask import Blueprint, request, session
2+
from flask import Blueprint, request, session, url_for
33
from flask import render_template, redirect, jsonify
44
from werkzeug.security import gen_salt
55
from authlib.integrations.flask_oauth2 import current_token
@@ -32,12 +32,17 @@ def home():
3232
db.session.add(user)
3333
db.session.commit()
3434
session['id'] = user.id
35+
# if user is not just to log in, but need to head back to the auth page, then go for it
36+
next_page = request.args.get('next')
37+
if next_page:
38+
return redirect(next_page)
3539
return redirect('/')
3640
user = current_user()
3741
if user:
3842
clients = OAuth2Client.query.filter_by(user_id=user.id).all()
3943
else:
4044
clients = []
45+
4146
return render_template('home.html', user=user, clients=clients)
4247

4348

@@ -87,6 +92,9 @@ def create_client():
8792
@bp.route('/oauth/authorize', methods=['GET', 'POST'])
8893
def authorize():
8994
user = current_user()
95+
# if user log status is not true (Auth server), then to log it in
96+
if not user:
97+
return redirect(url_for('website.routes.home', next=request.url))
9098
if request.method == 'GET':
9199
try:
92100
grant = authorization.validate_consent_request(end_user=user)

website/templates/authorize.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
<p>{{grant.client.client_name}} is requesting:
1+
<p>The application <strong>{{grant.client.client_name}}</strong> is requesting:
22
<strong>{{ grant.request.scope }}</strong>
33
</p>
44

5+
<p>
6+
from You - a.k.a. <strong>{{ user.username }}</strong>
7+
</p>
8+
59
<form action="" method="post">
610
<label>
711
<input type="checkbox" name="confirm">

0 commit comments

Comments
 (0)