@@ -8,6 +8,7 @@ namespace DotNetOpenAuth.Test.OAuth2 {
88 using System ;
99 using System . Collections . Generic ;
1010 using System . Linq ;
11+ using System . Net ;
1112 using System . Net . Http ;
1213 using System . Text ;
1314 using System . Threading ;
@@ -65,6 +66,7 @@ public async Task DecodeRefreshToken() {
6566 try {
6667 var authState = new AuthorizationState ( TestScopes ) { Callback = ClientCallback , } ;
6768 var authRedirectResponse = await client . PrepareRequestUserAuthorizationAsync ( authState ) ;
69+ this . HostFactories . CookieContainer . SetCookies ( authRedirectResponse , ClientCallback ) ;
6870 Uri authCompleteUri ;
6971 using ( var httpClient = this . HostFactories . CreateHttpClient ( ) ) {
7072 using ( var response = await httpClient . GetAsync ( authRedirectResponse . Headers . Location ) ) {
@@ -74,7 +76,7 @@ public async Task DecodeRefreshToken() {
7476 }
7577
7678 var authCompleteRequest = new HttpRequestMessage ( HttpMethod . Get , authCompleteUri ) ;
77- authCompleteRequest . Headers . Add ( "Cookie" , string . Join ( "; " , authRedirectResponse . Headers . GetValues ( "Set-Cookie" ) ) ) ;
79+ this . HostFactories . CookieContainer . ApplyCookies ( authCompleteRequest ) ;
7880 var result = await client . ProcessUserAuthorizationAsync ( authCompleteRequest ) ;
7981 Assert . That ( result . AccessToken , Is . Not . Null . And . Not . Empty ) ;
8082 Assert . That ( result . RefreshToken , Is . Not . Null . And . Not . Empty ) ;
@@ -147,7 +149,7 @@ public async Task CreateAccessTokenSeesAuthorizingUserClientCredentialGrant() {
147149 return await server . HandleTokenRequestAsync ( req , ct ) ;
148150 } ) ;
149151
150- var client = new WebServerClient ( AuthorizationServerDescription , hostFactories : this . HostFactories ) ;
152+ var client = new WebServerClient ( AuthorizationServerDescription , ClientId , ClientSecret , this . HostFactories ) ;
151153 var result = await client . GetClientAccessTokenAsync ( TestScopes ) ;
152154 Assert . That ( result . AccessToken , Is . Not . Null ) ;
153155 }
@@ -162,7 +164,7 @@ public async Task CreateAccessTokenSeesAuthorizingUserAuthorizationCodeGrant() {
162164 return true ;
163165 } ) ;
164166
165- Handle ( AuthorizationServerDescription . TokenEndpoint ) . By (
167+ Handle ( AuthorizationServerDescription . AuthorizationEndpoint ) . By (
166168 async ( req , ct ) => {
167169 var server = new AuthorizationServer ( authServerMock . Object ) ;
168170 var request = await server . ReadAuthorizationRequestAsync ( req , ct ) ;
@@ -181,15 +183,18 @@ public async Task CreateAccessTokenSeesAuthorizingUserAuthorizationCodeGrant() {
181183 Callback = ClientCallback ,
182184 } ;
183185 var authRedirectResponse = await client . PrepareRequestUserAuthorizationAsync ( authState ) ;
186+ this . HostFactories . CookieContainer . SetCookies ( authRedirectResponse , ClientCallback ) ;
184187 Uri authCompleteUri ;
188+ this . HostFactories . AllowAutoRedirects = false ;
185189 using ( var httpClient = this . HostFactories . CreateHttpClient ( ) ) {
186190 using ( var response = await httpClient . GetAsync ( authRedirectResponse . Headers . Location ) ) {
187- response . EnsureSuccessStatusCode ( ) ;
191+ Assert . That ( response . StatusCode , Is . EqualTo ( HttpStatusCode . Redirect ) ) ;
188192 authCompleteUri = response . Headers . Location ;
189193 }
190194 }
191195
192196 var authCompleteRequest = new HttpRequestMessage ( HttpMethod . Get , authCompleteUri ) ;
197+ this . HostFactories . CookieContainer . ApplyCookies ( authCompleteRequest ) ;
193198 var result = await client . ProcessUserAuthorizationAsync ( authCompleteRequest ) ;
194199 Assert . That ( result . AccessToken , Is . Not . Null . And . Not . Empty ) ;
195200 Assert . That ( result . RefreshToken , Is . Not . Null . And . Not . Empty ) ;
0 commit comments