#NEWLINE# def _collect_user_info( self , session , userinfo_claims = None ) : #NEWLINE# #INDENT# '\n        Collect information about a user.\n        This can happen in two cases, either when constructing an IdToken or\n        when returning user info through the UserInfo endpoint\n\n        :param session: Session information\n        :param userinfo_claims: user info claims\n        :return: User info\n        ' #NEWLINE# if ( userinfo_claims is None ) : #NEWLINE# #INDENT# uic = scope2claims ( session [ 'scope' ] ) #NEWLINE# perm_set = session . get ( 'permission' ) #NEWLINE# if perm_set : #NEWLINE# #INDENT# uic = { key : uic [ key ] for key in uic if ( key in userinfo_claims ) } #NEWLINE# #UNINDENT# if ( 'oidreq' in session ) : #NEWLINE# #INDENT# uic = self . server . update_claims ( session , 'oidreq' , 'userinfo' , uic ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# uic = self . server . update_claims ( session , 'authzreq' , 'userinfo' , uic ) #NEWLINE# #UNINDENT# if uic : #NEWLINE# #INDENT# userinfo_claims = Claims ( ** uic ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# userinfo_claims = None #NEWLINE# #UNINDENT# logger . debug ( ( 'userinfo_claim: %s' % userinfo_claims . to_dict ( ) ) ) #NEWLINE# #UNINDENT# logger . debug ( ( 'Session info: %s' % session ) ) #NEWLINE# authn_event = session . get ( 'authn_event' ) #NEWLINE# if authn_event : #NEWLINE# #INDENT# uid = authn_event . uid #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# uid = session [ 'uid' ] #NEWLINE# #UNINDENT# info = self . userinfo ( uid , session [ 'client_id' ] , userinfo_claims ) #NEWLINE# if ( 'sub' in userinfo_claims ) : #NEWLINE# #INDENT# if ( not claims_match ( session [ 'sub' ] , userinfo_claims [ 'sub' ] ) ) : #NEWLINE# #INDENT# raise FailedAuthentication ( 'Unmatched sub claim' ) #NEWLINE# #UNINDENT# #UNINDENT# info [ 'sub' ] = session [ 'sub' ] #NEWLINE# logger . debug ( ( 'user_info_response: %s' % ( info , ) ) ) #NEWLINE# return info