#NEWLINE# def do_client_registration( self , request , client_id , ignore = None ) : #NEWLINE# #INDENT# if ( ignore is None ) : #NEWLINE# #INDENT# ignore = [ ] #NEWLINE# #UNINDENT# _cinfo = self . cdb [ client_id ] . copy ( ) #NEWLINE# logger . debug ( ( '_cinfo: %s' % _cinfo ) ) #NEWLINE# for ( key , val ) in request . items ( ) : #NEWLINE# #INDENT# if ( key not in ignore ) : #NEWLINE# #INDENT# _cinfo [ key ] = val #NEWLINE# #UNINDENT# #UNINDENT# if ( 'post_logout_redirect_uris' in request ) : #NEWLINE# #INDENT# plruri = [ ] #NEWLINE# for uri in request [ 'post_logout_redirect_uris' ] : #NEWLINE# #INDENT# if urlparse ( uri ) . fragment : #NEWLINE# #INDENT# err = ClientRegistrationErrorResponse ( error = 'invalid_configuration_parameter' , error_description = 'post_logout_redirect_uris contains fragment' ) #NEWLINE# return Response ( err . to_json ( ) , content = 'application/json' , status = '400 Bad Request' ) #NEWLINE# #UNINDENT# ( base , query ) = splitquery ( uri ) #NEWLINE# if query : #NEWLINE# #INDENT# plruri . append ( ( base , parse_qs ( query ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# plruri . append ( ( base , query ) ) #NEWLINE# #UNINDENT# #UNINDENT# _cinfo [ 'post_logout_redirect_uris' ] = plruri #NEWLINE# #UNINDENT# if ( 'redirect_uris' in request ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ruri = self . _verify_redirect_uris ( request ) #NEWLINE# _cinfo [ 'redirect_uris' ] = ruri #NEWLINE# #UNINDENT# except InvalidRedirectURIError as e : #NEWLINE# #INDENT# err = ClientRegistrationErrorResponse ( error = 'invalid_redirect_uri' , error_description = str ( e ) ) #NEWLINE# return Response ( err . to_json ( ) , content = 'application/json' , status = '400 Bad Request' ) #NEWLINE# #UNINDENT# #UNINDENT# if ( 'sector_identifier_uri' in request ) : #NEWLINE# #INDENT# si_url = request [ 'sector_identifier_uri' ] #NEWLINE# try : #NEWLINE# #INDENT# res = self . server . http_request ( si_url ) #NEWLINE# #UNINDENT# except ConnectionError as err : #NEWLINE# #INDENT# logger . error ( ( '%s' % err ) ) #NEWLINE# return self . _error_response ( 'invalid_configuration_parameter' , descr = "Couldn't open sector_identifier_uri" ) #NEWLINE# #UNINDENT# if ( not res ) : #NEWLINE# #INDENT# return self . _error_response ( 'invalid_configuration_parameter' , descr = "Couldn't open sector_identifier_uri" ) #NEWLINE# #UNINDENT# logger . debug ( ( 'sector_identifier_uri => %s' % res . text ) ) #NEWLINE# try : #NEWLINE# #INDENT# si_redirects = json . loads ( res . text ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# return self . _error_response ( 'invalid_configuration_parameter' , descr = 'Error deserializing sector_identifier_uri content' ) #NEWLINE# #UNINDENT# if ( 'redirect_uris' in request ) : #NEWLINE# #INDENT# logger . debug ( ( 'redirect_uris: %s' % request [ 'redirect_uris' ] ) ) #NEWLINE# for uri in request [ 'redirect_uris' ] : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# assert ( uri in si_redirects ) #NEWLINE# #UNINDENT# except AssertionError : #NEWLINE# #INDENT# return self . _error_response ( 'invalid_configuration_parameter' , descr = 'redirect_uri missing from sector_identifiers' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# _cinfo [ 'si_redirects' ] = si_redirects #NEWLINE# _cinfo [ 'sector_id' ] = si_url #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( 'redirect_uris' in request ) : #NEWLINE# #INDENT# if ( len ( request [ 'redirect_uris' ] ) > 1 ) : #NEWLINE# #INDENT# host = '' #NEWLINE# for url in request [ 'redirect_uris' ] : #NEWLINE# #INDENT# part = urlparse ( url ) #NEWLINE# _host = part . netloc . split ( ':' ) [ 0 ] #NEWLINE# if ( not host ) : #NEWLINE# #INDENT# host = _host #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# assert ( host == _host ) #NEWLINE# #UNINDENT# except AssertionError : #NEWLINE# #INDENT# return self . _error_response ( 'invalid_configuration_parameter' , descr = "'sector_identifier_uri' must be registered" ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# for item in [ 'policy_uri' , 'logo_uri' , 'tos_uri' ] : #NEWLINE# #INDENT# if ( item in request ) : #NEWLINE# #INDENT# if self . _verify_url ( request [ item ] , _cinfo [ 'redirect_uris' ] ) : #NEWLINE# #INDENT# _cinfo [ item ] = request [ item ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return self . _error_response ( 'invalid_configuration_parameter' , descr = ( '%s pointed to illegal URL' % item ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# for item in [ 'id_token_signed_response_alg' , 'userinfo_signed_response_alg' ] : #NEWLINE# #INDENT# if ( item in request ) : #NEWLINE# #INDENT# if ( request [ item ] in self . capabilities [ PREFERENCE2PROVIDER [ item ] ] ) : #NEWLINE# #INDENT# ktyp = jws . alg2keytype ( request [ item ] ) #NEWLINE# if ( url not in [ 'none' , 'oct' ] ) : #NEWLINE# #INDENT# _k = self . keyjar . get_signing_key ( ktyp , alg = request [ item ] ) #NEWLINE# if ( not _k ) : #NEWLINE# #INDENT# del _cinfo [ item ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# self . keyjar . load_keys ( request , client_id ) #NEWLINE# try : #NEWLINE# #INDENT# logger . debug ( ( 'keys for %s: [%s]' % ( client_id , ',' . join ( [ ( '%s' % x ) for x in self . keyjar [ client_id ] ] ) ) ) ) #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# except Exception as err : #NEWLINE# #INDENT# logger . error ( ( 'Failed to load client keys: %s' % request . to_dict ( ) ) ) #NEWLINE# logger . error ( '%s' , err ) #NEWLINE# err = ClientRegistrationErrorResponse ( error = 'invalid_configuration_parameter' , error_description = ( '%s' % err ) ) #NEWLINE# return Response ( err . to_json ( ) , content = 'application/json' , status = '400 Bad Request' ) #NEWLINE# #UNINDENT# return _cinfo