66 let ( :client_secret ) { 'test-client-secret' }
77 let ( :api_identifier ) { 'test-audience' }
88 let ( :domain ) { 'samples.auth0.com' }
9+ let ( :request_uri ) { 'urn:ietf:params:oauth:request_uri:the.request.uri' }
910
1011 let ( :client_secret_config ) { {
1112 domain : domain ,
628629 client_assertion_instance . send :start_passwordless_sms_flow , '123456789'
629630 end
630631 end
632+
633+ context 'par_authorization_url' do
634+ it 'throws an exception if request_uri is nil' do
635+ expect { client_secret_instance . send :par_authorization_url , nil } . to raise_error Auth0 ::InvalidParameter
636+ end
637+
638+ it 'throws an exception if request_uri is empty' do
639+ expect { client_secret_instance . send :par_authorization_url , '' } . to raise_error Auth0 ::InvalidParameter
640+ end
641+
642+ it 'builds a URL containing the request_uri' do
643+ url = client_secret_instance . send :par_authorization_url , request_uri
644+ expect ( CGI . unescape ( url . to_s ) ) . to eq ( "https://samples.auth0.com/authorize?client_id=#{ client_id } &request_uri=#{ request_uri } " )
645+ end
646+ end
647+
648+ context 'pushed_authorization_request' do
649+ it 'sends the request as a form post' do
650+ expect ( RestClient ::Request ) . to receive ( :execute ) do |arg |
651+ expect ( arg [ :url ] ) . to eq ( 'https://samples.auth0.com/oauth/par' )
652+ expect ( arg [ :method ] ) . to eq ( :post )
653+
654+ expect ( arg [ :payload ] ) . to eq ( {
655+ client_id : client_id ,
656+ client_secret : client_secret ,
657+ response_type : 'code' ,
658+ } )
659+
660+ StubResponse . new ( { } , true , 200 )
661+ end
662+
663+ client_secret_instance . send :pushed_authorization_request
664+ end
665+
666+ it 'allows the RestClient to handle the correct header defaults' do
667+ expect ( RestClient ::Request ) . to receive ( :execute ) do |arg |
668+ expect ( arg [ :headers ] ) . not_to have_key ( 'Content-Type' )
669+
670+ StubResponse . new ( { } , true , 200 )
671+ end
672+
673+ client_secret_instance . headers [ 'Content-Type' ] = 'application/x-www-form-urlencoded'
674+ client_secret_instance . send :pushed_authorization_request
675+ end
676+
677+ it 'sends the request as a form post with all known overrides' do
678+ expect ( RestClient ::Request ) . to receive ( :execute ) do |arg |
679+ expect ( arg [ :url ] ) . to eq ( 'https://samples.auth0.com/oauth/par' )
680+ expect ( arg [ :method ] ) . to eq ( :post )
681+
682+ expect ( arg [ :payload ] ) . to eq ( {
683+ client_id : client_id ,
684+ client_secret : client_secret ,
685+ connection : 'google-oauth2' ,
686+ organization : 'org_id' ,
687+ invitation : 'http://invite.url' ,
688+ redirect_uri : 'http://localhost:3000' ,
689+ response_type : 'id_token' ,
690+ scope : 'openid' ,
691+ state : 'random_value'
692+ } )
693+
694+ StubResponse . new ( { } , true , 200 )
695+ end
696+
697+ client_secret_instance . send ( :pushed_authorization_request ,
698+ response_type : 'id_token' ,
699+ redirect_uri : 'http://localhost:3000' ,
700+ organization : 'org_id' ,
701+ invitation : 'http://invite.url' ,
702+ scope : 'openid' ,
703+ state : 'random_value' ,
704+ connection : 'google-oauth2' )
705+ end
706+
707+ it 'sends the request as a form post using client assertion' do
708+ expect ( RestClient ::Request ) . to receive ( :execute ) do |arg |
709+ expect ( arg [ :url ] ) . to eq ( 'https://samples.auth0.com/oauth/par' )
710+ expect ( arg [ :method ] ) . to eq ( :post )
711+ expect ( arg [ :payload ] [ :client_secret ] ) . to be_nil
712+ expect ( arg [ :payload ] [ :client_assertion ] ) . not_to be_nil
713+ expect ( arg [ :payload ] [ :client_assertion_type ] ) . to eq Auth0 ::ClientAssertion ::CLIENT_ASSERTION_TYPE
714+
715+ StubResponse . new ( { } , true , 200 )
716+ end
717+
718+ client_assertion_instance . send :pushed_authorization_request
719+ end
720+ end
631721 end
632722end
0 commit comments