@@ -420,6 +420,50 @@ public async Task ReplyPathWithAccessDeniedError_AllowsCustomizingPath()
420
420
Assert . Equal ( "/custom-denied-page?rurl=http%3A%2F%2Fwww.google.com%2F" , transaction . Response . Headers . GetValues ( "Location" ) . First ( ) ) ;
421
421
}
422
422
423
+ [ Fact ]
424
+ public async Task ReplyPathWithAccessDeniedErrorAndNoAccessDeniedPath_FallsBackToRemoteError ( )
425
+ {
426
+ var accessDeniedCalled = false ;
427
+ var remoteFailureCalled = false ;
428
+ var server = CreateServer ( o =>
429
+ {
430
+ o . ClientId = "Test Id" ;
431
+ o . ClientSecret = "Test Secret" ;
432
+ o . StateDataFormat = new TestStateDataFormat ( ) ;
433
+ o . Events = new OAuthEvents ( )
434
+ {
435
+ OnAccessDenied = ctx =>
436
+ {
437
+ Assert . Null ( ctx . AccessDeniedPath . Value ) ;
438
+ Assert . Equal ( "http://testhost/redirect" , ctx . ReturnUrl ) ;
439
+ Assert . Equal ( "ReturnUrl" , ctx . ReturnUrlParameter ) ;
440
+ accessDeniedCalled = true ;
441
+ return Task . FromResult ( 0 ) ;
442
+ } ,
443
+ OnRemoteFailure = ctx =>
444
+ {
445
+ var ex = ctx . Failure ;
446
+ Assert . True ( ex . Data . Contains ( "error" ) , "error" ) ;
447
+ Assert . True ( ex . Data . Contains ( "error_description" ) , "error_description" ) ;
448
+ Assert . True ( ex . Data . Contains ( "error_uri" ) , "error_uri" ) ;
449
+ Assert . Equal ( "access_denied" , ex . Data [ "error" ] ) ;
450
+ Assert . Equal ( "whyitfailed" , ex . Data [ "error_description" ] ) ;
451
+ Assert . Equal ( "https://example.com/fail" , ex . Data [ "error_uri" ] ) ;
452
+ remoteFailureCalled = true ;
453
+ ctx . Response . Redirect ( "/error?FailureMessage=" + UrlEncoder . Default . Encode ( ctx . Failure . Message ) ) ;
454
+ ctx . HandleResponse ( ) ;
455
+ return Task . FromResult ( 0 ) ;
456
+ }
457
+ } ;
458
+ } ) ;
459
+ var transaction = await server . SendAsync ( "https://example.com/signin-google?error=access_denied&error_description=whyitfailed&error_uri=https://example.com/fail&state=protected_state" ,
460
+ ".AspNetCore.Correlation.Google.correlationId=N" ) ;
461
+ Assert . Equal ( HttpStatusCode . Redirect , transaction . Response . StatusCode ) ;
462
+ Assert . StartsWith ( "/error?FailureMessage=" , transaction . Response . Headers . GetValues ( "Location" ) . First ( ) ) ;
463
+ Assert . True ( accessDeniedCalled ) ;
464
+ Assert . True ( remoteFailureCalled ) ;
465
+ }
466
+
423
467
[ Theory ]
424
468
[ InlineData ( true ) ]
425
469
[ InlineData ( false ) ]
@@ -434,24 +478,31 @@ public async Task ReplyPathWithErrorFails(bool redirect)
434
478
{
435
479
OnRemoteFailure = ctx =>
436
480
{
481
+ var ex = ctx . Failure ;
482
+ Assert . True ( ex . Data . Contains ( "error" ) , "error" ) ;
483
+ Assert . True ( ex . Data . Contains ( "error_description" ) , "error_description" ) ;
484
+ Assert . True ( ex . Data . Contains ( "error_uri" ) , "error_uri" ) ;
485
+ Assert . Equal ( "itfailed" , ex . Data [ "error" ] ) ;
486
+ Assert . Equal ( "whyitfailed" , ex . Data [ "error_description" ] ) ;
487
+ Assert . Equal ( "https://example.com/fail" , ex . Data [ "error_uri" ] ) ;
437
488
ctx . Response . Redirect ( "/error?FailureMessage=" + UrlEncoder . Default . Encode ( ctx . Failure . Message ) ) ;
438
489
ctx . HandleResponse ( ) ;
439
490
return Task . FromResult ( 0 ) ;
440
491
}
441
492
} : new OAuthEvents ( ) ;
442
493
} ) ;
443
- var sendTask = server . SendAsync ( "https://example.com/signin-google?error=OMG &error_description=SoBad &error_uri=foobar &state=protected_state" ,
494
+ var sendTask = server . SendAsync ( "https://example.com/signin-google?error=itfailed &error_description=whyitfailed &error_uri=https://example.com/fail &state=protected_state" ,
444
495
".AspNetCore.Correlation.Google.correlationId=N" ) ;
445
496
if ( redirect )
446
497
{
447
498
var transaction = await sendTask ;
448
499
Assert . Equal ( HttpStatusCode . Redirect , transaction . Response . StatusCode ) ;
449
- Assert . Equal ( "/error?FailureMessage=OMG " + UrlEncoder . Default . Encode ( ";Description=SoBad ;Uri=foobar " ) , transaction . Response . Headers . GetValues ( "Location" ) . First ( ) ) ;
500
+ Assert . Equal ( "/error?FailureMessage=itfailed " + UrlEncoder . Default . Encode ( ";Description=whyitfailed ;Uri=https://example.com/fail " ) , transaction . Response . Headers . GetValues ( "Location" ) . First ( ) ) ;
450
501
}
451
502
else
452
503
{
453
504
var error = await Assert . ThrowsAnyAsync < Exception > ( ( ) => sendTask ) ;
454
- Assert . Equal ( "OMG ;Description=SoBad ;Uri=foobar " , error . GetBaseException ( ) . Message ) ;
505
+ Assert . Equal ( "itfailed ;Description=whyitfailed ;Uri=https://example.com/fail " , error . GetBaseException ( ) . Message ) ;
455
506
}
456
507
}
457
508
0 commit comments