@@ -398,6 +398,10 @@ def decorated(*args, **kwargs):
398
398
return redirect (e .in_uri (self .error_uri ))
399
399
except oauth2 .OAuth2Error as e :
400
400
log .debug ('OAuth2Error: %r' , e , exc_info = True )
401
+ # on auth error, we should preserve state if it's present according to RFC 6749
402
+ state = request .values .get ('state' )
403
+ if state and not e .state :
404
+ e .state = state # set e.state so e.in_uri() can add the state query parameter to redirect uri
401
405
return redirect (e .in_uri (redirect_uri ))
402
406
except Exception as e :
403
407
log .exception (e )
@@ -417,6 +421,10 @@ def decorated(*args, **kwargs):
417
421
return redirect (e .in_uri (self .error_uri ))
418
422
except oauth2 .OAuth2Error as e :
419
423
log .debug ('OAuth2Error: %r' , e , exc_info = True )
424
+ # on auth error, we should preserve state if it's present according to RFC 6749
425
+ state = request .values .get ('state' )
426
+ if state and not e .state :
427
+ e .state = state # set e.state so e.in_uri() can add the state query parameter to redirect uri
420
428
return redirect (e .in_uri (redirect_uri ))
421
429
422
430
if not isinstance (rv , bool ):
@@ -425,7 +433,7 @@ def decorated(*args, **kwargs):
425
433
426
434
if not rv :
427
435
# denied by user
428
- e = oauth2 .AccessDeniedError ()
436
+ e = oauth2 .AccessDeniedError (state = request . values . get ( 'state' ) )
429
437
return redirect (e .in_uri (redirect_uri ))
430
438
return self .confirm_authorization_request ()
431
439
return decorated
@@ -456,6 +464,10 @@ def confirm_authorization_request(self):
456
464
return redirect (e .in_uri (self .error_uri ))
457
465
except oauth2 .OAuth2Error as e :
458
466
log .debug ('OAuth2Error: %r' , e , exc_info = True )
467
+ # on auth error, we should preserve state if it's present according to RFC 6749
468
+ state = request .values .get ('state' )
469
+ if state and not e .state :
470
+ e .state = state # set e.state so e.in_uri() can add the state query parameter to redirect uri
459
471
return redirect (e .in_uri (redirect_uri or self .error_uri ))
460
472
except Exception as e :
461
473
log .exception (e )
0 commit comments