#NEWLINE# def authenticate( self , request ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# payload = jwt . decode ( jwe . decrypt ( request . body , settings . JWE_SECRET ) , settings . JWT_SECRET , options = { #NEWLINE# #INDENT# 'verify_exp' : False , #NEWLINE# #UNINDENT# } , algorithm = 'HS256' ) #NEWLINE# #UNINDENT# except ( jwt . InvalidTokenError , TypeError ) : #NEWLINE# #INDENT# raise AuthenticationFailed #NEWLINE# #UNINDENT# data = json . loads ( payload [ 'data' ] ) #NEWLINE# provider = data [ 'provider' ] #NEWLINE# institution = Institution . load ( provider [ 'id' ] ) #NEWLINE# if ( not institution ) : #NEWLINE# #INDENT# raise AuthenticationFailed ( 'Invalid institution id specified "{}"' . format ( provider [ 'id' ] ) ) #NEWLINE# #UNINDENT# username = provider [ 'user' ] [ 'username' ] #NEWLINE# fullname = provider [ 'user' ] [ 'fullname' ] #NEWLINE# ( user , created ) = get_or_create_user ( fullname , username ) #NEWLINE# if created : #NEWLINE# #INDENT# user . given_name = provider [ 'user' ] . get ( 'givenName' ) #NEWLINE# user . middle_names = provider [ 'user' ] . get ( 'middleNames' ) #NEWLINE# user . family_name = provider [ 'user' ] . get ( 'familyName' ) #NEWLINE# user . suffix = provider [ 'user' ] . get ( 'suffix' ) #NEWLINE# user . date_last_login = datetime . utcnow ( ) #NEWLINE# user . save ( ) #NEWLINE# user . register ( username ) #NEWLINE# send_mail ( to_addr = self . username , mail = WELCOME_OSF4I , mimetype = 'html' , user = user ) #NEWLINE# #UNINDENT# if ( institution not in user . affiliated_institutions ) : #NEWLINE# #INDENT# user . affiliated_institutions . append ( institution ) #NEWLINE# user . save ( ) #NEWLINE# #UNINDENT# return ( user , None )