File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -143,6 +143,38 @@ def user_logout():
143
143
return jsonify ("Logged out " + username )
144
144
145
145
146
+ # Generate a new access token
147
+
148
+ @user_api .route ("/api/user/refresh" , methods = ["GET" ])
149
+ @jwt_ops .jwt_required ()
150
+ def user_refresh ():
151
+ """ If user still active, send back an access_token with a new expiration stamp """
152
+ old_jwt = jwt_ops .validate_decode_jwt ()
153
+
154
+ # If token bad, should be handled & error message sent by jwt_required() and we won't get here
155
+ if old_jwt :
156
+ user_name = old_jwt ['sub' ]
157
+ with engine .connect () as connection :
158
+
159
+ s = text ( """select active from pdp_users where username=:u """ )
160
+ s = s .bindparams (u = user_name )
161
+ result = connection .execute (s )
162
+
163
+ if result .rowcount : # Did we get a match on username?
164
+ is_active = result .fetchone ()
165
+ else :
166
+ log_user_action (user_name , "Failure" , "Valid JWT presented for refesh attempt on unknown username" )
167
+ return jsonify ("Bad credentials" ), 401
168
+
169
+ if is_active [0 ].lower () == 'y' : # In the user DB and still Active?
170
+ token = jwt_ops .create_token (user_name ,old_jwt ['role' ])
171
+ return token
172
+
173
+ else :
174
+ return jsonify ("Bad credentials" ), 401
175
+
176
+
177
+
146
178
### Unexpired *Admin* JWT required ############################
147
179
148
180
You can’t perform that action at this time.
0 commit comments