#NEWLINE# def authenticate_or_redirect( self ) : #NEWLINE# #INDENT# '\n        Helper function suitable for @app.before_request and @check (below).\n        Sets g.oidc_id_token to the ID token if the user has successfully\n        authenticated, else returns a redirect object so they can go try\n        to authenticate.\n        :return: A redirect, or None if the user is authenticated.\n        ' #NEWLINE# if ( request . endpoint in frozenset ( [ 'oidc_callback' , 'oidc_error' ] ) ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# id_token = self . get_cookie_id_token ( ) #NEWLINE# if ( id_token is None ) : #NEWLINE# #INDENT# return self . redirect_to_auth_server ( request . url ) #NEWLINE# #UNINDENT# if ( self . time ( ) >= id_token [ 'exp' ] ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# credentials = self . credentials_store [ id_token [ 'sub' ] ] #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# logger . debug ( 'Expired ID token, credentials missing' , exc_info = True ) #NEWLINE# return self . redirect_to_auth_server ( request . url ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# credentials . refresh ( self . http ) #NEWLINE# id_token = credentials . id_token #NEWLINE# self . credentials_store [ id_token [ 'sub' ] ] = credentials #NEWLINE# self . set_cookie_id_token ( id_token ) #NEWLINE# #UNINDENT# except AccessTokenRefreshError : #NEWLINE# #INDENT# logger . debug ( "Expired ID token, can't refresh credentials" , exc_info = True ) #NEWLINE# del self . credentials_store [ id_token [ 'sub' ] ] #NEWLINE# return self . redirect_to_auth_server ( request . url ) #NEWLINE# #UNINDENT# #UNINDENT# g . oidc_id_token = id_token #NEWLINE# return None