@@ -174,6 +174,89 @@ await Assert.ThrowsAsync<ArgumentException>(() =>
174174 client . GetAuthorizationCodeAsync ( expectedScopes , browser , extraParams , CancellationToken . None ) ) ;
175175 }
176176
177+ [ Theory ]
178+ [ InlineData ( OAuth2ResponseMode . Query , "query" ) ]
179+ [ InlineData ( OAuth2ResponseMode . Fragment , "fragment" ) ]
180+ [ InlineData ( OAuth2ResponseMode . FormPost , "form_post" ) ]
181+ public async Task OAuth2Client_GetAuthorizationCodeAsync_NonDefaultResponseMode_SendsResponseModeParameter (
182+ OAuth2ResponseMode responseMode , string expectedValue )
183+ {
184+ const string expectedAuthCode = "68c39cbd8d" ;
185+
186+ var baseUri = new Uri ( "https://example.com" ) ;
187+ OAuth2ServerEndpoints endpoints = CreateEndpoints ( baseUri ) ;
188+
189+ var httpHandler = new TestHttpMessageHandler { ThrowOnUnexpectedRequest = true } ;
190+
191+ string [ ] expectedScopes = { "read" , "write" , "delete" } ;
192+
193+ OAuth2Application app = CreateTestApplication ( ) ;
194+
195+ var server = new TestOAuth2Server ( endpoints ) ;
196+ server . RegisterApplication ( app ) ;
197+ server . Bind ( httpHandler ) ;
198+ server . TokenGenerator . AuthCodes . Add ( expectedAuthCode ) ;
199+
200+ server . AuthorizationEndpointInvoked += ( _ , request ) =>
201+ {
202+ IDictionary < string , string > actualParams = request . RequestUri . GetQueryParameters ( ) ;
203+ Assert . True ( actualParams . TryGetValue (
204+ OAuth2Constants . AuthorizationEndpoint . ResponseModeParameter , out string actualMode ) ) ;
205+ Assert . Equal ( expectedValue , actualMode ) ;
206+ } ;
207+
208+ IOAuth2WebBrowser browser = new TestOAuth2WebBrowser ( httpHandler ) ;
209+
210+ var trace2 = new NullTrace2 ( ) ;
211+ OAuth2Client client = new OAuth2Client (
212+ new HttpClient ( httpHandler ) , endpoints , TestClientId , trace2 ,
213+ TestRedirectUri , TestClientSecret , responseMode : responseMode ) ;
214+
215+ OAuth2AuthorizationCodeResult result = await client . GetAuthorizationCodeAsync (
216+ expectedScopes , browser , null , CancellationToken . None ) ;
217+
218+ Assert . Equal ( expectedAuthCode , result . Code ) ;
219+ }
220+
221+ [ Fact ]
222+ public async Task OAuth2Client_GetAuthorizationCodeAsync_DefaultResponseMode_OmitsResponseModeParameter ( )
223+ {
224+ const string expectedAuthCode = "68c39cbd8d" ;
225+
226+ var baseUri = new Uri ( "https://example.com" ) ;
227+ OAuth2ServerEndpoints endpoints = CreateEndpoints ( baseUri ) ;
228+
229+ var httpHandler = new TestHttpMessageHandler { ThrowOnUnexpectedRequest = true } ;
230+
231+ string [ ] expectedScopes = { "read" , "write" , "delete" } ;
232+
233+ OAuth2Application app = CreateTestApplication ( ) ;
234+
235+ var server = new TestOAuth2Server ( endpoints ) ;
236+ server . RegisterApplication ( app ) ;
237+ server . Bind ( httpHandler ) ;
238+ server . TokenGenerator . AuthCodes . Add ( expectedAuthCode ) ;
239+
240+ server . AuthorizationEndpointInvoked += ( _ , request ) =>
241+ {
242+ IDictionary < string , string > actualParams = request . RequestUri . GetQueryParameters ( ) ;
243+ Assert . False ( actualParams . ContainsKey (
244+ OAuth2Constants . AuthorizationEndpoint . ResponseModeParameter ) ) ;
245+ } ;
246+
247+ IOAuth2WebBrowser browser = new TestOAuth2WebBrowser ( httpHandler ) ;
248+
249+ var trace2 = new NullTrace2 ( ) ;
250+ OAuth2Client client = new OAuth2Client (
251+ new HttpClient ( httpHandler ) , endpoints , TestClientId , trace2 ,
252+ TestRedirectUri , TestClientSecret , responseMode : OAuth2ResponseMode . Default ) ;
253+
254+ OAuth2AuthorizationCodeResult result = await client . GetAuthorizationCodeAsync (
255+ expectedScopes , browser , null , CancellationToken . None ) ;
256+
257+ Assert . Equal ( expectedAuthCode , result . Code ) ;
258+ }
259+
177260 [ Fact ]
178261 public async Task OAuth2Client_GetDeviceCodeAsync ( )
179262 {
0 commit comments