提交 97aaead9239b4c17d81b3eacd5073d465f8932ae

作者 qianyingz
1 个父辈 62c596fe

解决无法获取accesstoken的问题

@@ -8,6 +8,7 @@ from .oauth2 import authorization, require_oauth, generate_user_info @@ -8,6 +8,7 @@ from .oauth2 import authorization, require_oauth, generate_user_info
8 from authlib.oauth2 import OAuth2Error 8 from authlib.oauth2 import OAuth2Error
9 from authlib.integrations.flask_oauth2 import current_token 9 from authlib.integrations.flask_oauth2 import current_token
10 10
  11 +
11 def current_user(): 12 def current_user():
12 if 'id' in session: 13 if 'id' in session:
13 uid = session['id'] 14 uid = session['id']
@@ -34,7 +35,7 @@ class DataManager(BlueprintApi): @@ -34,7 +35,7 @@ class DataManager(BlueprintApi):
34 35
35 @staticmethod 36 @staticmethod
36 @bp.route('/', methods=('GET', 'POST')) 37 @bp.route('/', methods=('GET', 'POST'))
37 - def test(): 38 + def Login():
38 if request.method == 'POST': 39 if request.method == 'POST':
39 username = request.form['username'] 40 username = request.form['username']
40 password = request.form['password'] 41 password = request.form['password']
@@ -52,8 +53,6 @@ class DataManager(BlueprintApi): @@ -52,8 +53,6 @@ class DataManager(BlueprintApi):
52 else: 53 else:
53 clients = [] 54 clients = []
54 return render_template('auth/login.html', user=user, clients=clients) 55 return render_template('auth/login.html', user=user, clients=clients)
55 -  
56 -  
57 56
58 @staticmethod 57 @staticmethod
59 @bp.route('/create_client', methods=('GET', 'POST')) 58 @bp.route('/create_client', methods=('GET', 'POST'))
@@ -85,7 +84,7 @@ class DataManager(BlueprintApi): @@ -85,7 +84,7 @@ class DataManager(BlueprintApi):
85 db.session.add(client) 84 db.session.add(client)
86 db.session.commit() 85 db.session.commit()
87 return redirect('/auth') 86 return redirect('/auth')
88 - 87 +
89 @staticmethod 88 @staticmethod
90 @bp.route('/authorize', methods=('GET', 'POST')) 89 @bp.route('/authorize', methods=('GET', 'POST'))
91 def authorize(): 90 def authorize():
@@ -104,13 +103,12 @@ class DataManager(BlueprintApi): @@ -104,13 +103,12 @@ class DataManager(BlueprintApi):
104 else: 103 else:
105 grant_user = None 104 grant_user = None
106 return authorization.create_authorization_response(grant_user=grant_user) 105 return authorization.create_authorization_response(grant_user=grant_user)
107 -  
108 - 106 +
109 @staticmethod 107 @staticmethod
110 @bp.route('/token', methods=['POST']) 108 @bp.route('/token', methods=['POST'])
111 def issue_token(): 109 def issue_token():
112 return authorization.create_token_response() 110 return authorization.create_token_response()
113 - 111 +
114 @staticmethod 112 @staticmethod
115 @bp.route('/userinfo') 113 @bp.route('/userinfo')
116 @require_oauth('profile') 114 @require_oauth('profile')
@@ -26,6 +26,7 @@ DUMMY_JWT_CONFIG = { @@ -26,6 +26,7 @@ DUMMY_JWT_CONFIG = {
26 'exp': 7200, 26 'exp': 7200,
27 } 27 }
28 28
  29 +
29 def exists_nonce(nonce, req): 30 def exists_nonce(nonce, req):
30 exists = OAuth2AuthorizationCode.query.filter_by( 31 exists = OAuth2AuthorizationCode.query.filter_by(
31 client_id=req.client_id, nonce=nonce 32 client_id=req.client_id, nonce=nonce
@@ -34,7 +35,7 @@ def exists_nonce(nonce, req): @@ -34,7 +35,7 @@ def exists_nonce(nonce, req):
34 35
35 36
36 def generate_user_info(user, scope): 37 def generate_user_info(user, scope):
37 - return UserInfo(sub=str(user.id), name=user.username) 38 + return UserInfo(sub=str(user.id), name=user.username, role=user.role, company=user.company)
38 39
39 40
40 def create_authorization_code(client, grant_user, request): 41 def create_authorization_code(client, grant_user, request):
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 # 程序部署ip:host 3 # 程序部署ip:host
4 deploy_ip_host = "172.26.99.160:8840" 4 deploy_ip_host = "172.26.99.160:8840"
5 # 系统数据库 5 # 系统数据库
6 -SQLALCHEMY_DATABASE_URI = "postgresql://postgres:postgres@172.26.40.254:5433/dmap_dms_test" 6 +SQLALCHEMY_DATABASE_URI = "postgresql://postgres:postgres@localhost:5433/dmap_dms_test"
7 7
8 8
9 # 部署模式cluster,standalone 9 # 部署模式cluster,standalone
注册登录 后发表评论