@@ -1010,75 +1010,6 @@ public async Task ExpirationAndIssuedWhenMinOrMaxValue()
1010
1010
Assert . Equal ( max , elementValueUtc ) ;
1011
1011
}
1012
1012
1013
- [ Fact ]
1014
- public void CanReadJwtBearerOptionsFromConfig ( )
1015
- {
1016
- var services = new ServiceCollection ( ) . AddLogging ( ) ;
1017
- var config = new ConfigurationBuilder ( ) . AddInMemoryCollection ( new [ ]
1018
- {
1019
- new KeyValuePair < string , string > ( "Authentication:Schemes:Bearer:ValidIssuer" , "dotnet-user-jwts" ) ,
1020
- new KeyValuePair < string , string > ( "Authentication:Schemes:Bearer:ValidAudiences:0" , "http://localhost:5000" ) ,
1021
- new KeyValuePair < string , string > ( "Authentication:Schemes:Bearer:ValidAudiences:1" , "https://localhost:5001" ) ,
1022
- new KeyValuePair < string , string > ( "Authentication:Schemes:Bearer:BackchannelTimeout" , "00:01:00" ) ,
1023
- new KeyValuePair < string , string > ( "Authentication:Schemes:Bearer:RequireHttpsMetadata" , "false" ) ,
1024
- new KeyValuePair < string , string > ( "Authentication:Schemes:Bearer:SaveToken" , "True" ) ,
1025
- } ) . Build ( ) ;
1026
- services . AddSingleton < IConfiguration > ( config ) ;
1027
-
1028
- // Act
1029
- var builder = services . AddAuthentication ( o =>
1030
- {
1031
- o . AddScheme < TestHandler > ( "Bearer" , "Bearer" ) ;
1032
- } ) ;
1033
- builder . AddJwtBearer ( "Bearer" , o => o . UseSecurityTokenValidators = true ) ;
1034
- RegisterAuth ( builder , _ => { } ) ;
1035
- var sp = services . BuildServiceProvider ( ) ;
1036
-
1037
- // Assert
1038
- var jwtBearerOptions = sp . GetRequiredService < IOptionsMonitor < JwtBearerOptions > > ( ) . Get ( JwtBearerDefaults . AuthenticationScheme ) ;
1039
- Assert . Equal ( jwtBearerOptions . TokenValidationParameters . ValidIssuers , new [ ] { "dotnet-user-jwts" } ) ;
1040
- Assert . Equal ( jwtBearerOptions . TokenValidationParameters . ValidAudiences , new [ ] { "http://localhost:5000" , "https://localhost:5001" } ) ;
1041
- Assert . Equal ( jwtBearerOptions . BackchannelTimeout , TimeSpan . FromSeconds ( 60 ) ) ;
1042
- Assert . False ( jwtBearerOptions . RequireHttpsMetadata ) ;
1043
- Assert . True ( jwtBearerOptions . SaveToken ) ;
1044
- Assert . True ( jwtBearerOptions . MapInboundClaims ) ; // Assert default values are respected
1045
- }
1046
-
1047
- [ Fact ]
1048
- public void CanReadMultipleIssuersFromConfig ( )
1049
- {
1050
- var services = new ServiceCollection ( ) . AddLogging ( ) ;
1051
- var firstKey = "qPG6tDtfxFYZifHW3sEueQ==" ;
1052
- var secondKey = "6JPzXj6aOPdojlZdeLshaA==" ;
1053
- var config = new ConfigurationBuilder ( ) . AddInMemoryCollection ( new [ ]
1054
- {
1055
- new KeyValuePair < string , string > ( "Authentication:Schemes:Bearer:ValidIssuers:0" , "dotnet-user-jwts" ) ,
1056
- new KeyValuePair < string , string > ( "Authentication:Schemes:Bearer:ValidIssuers:1" , "dotnet-user-jwts-2" ) ,
1057
- new KeyValuePair < string , string > ( "Authentication:Schemes:Bearer:SigningKeys:0:Issuer" , "dotnet-user-jwts" ) ,
1058
- new KeyValuePair < string , string > ( "Authentication:Schemes:Bearer:SigningKeys:0:Value" , firstKey ) ,
1059
- new KeyValuePair < string , string > ( "Authentication:Schemes:Bearer:SigningKeys:0:Length" , "32" ) ,
1060
- new KeyValuePair < string , string > ( "Authentication:Schemes:Bearer:SigningKeys:1:Issuer" , "dotnet-user-jwts-2" ) ,
1061
- new KeyValuePair < string , string > ( "Authentication:Schemes:Bearer:SigningKeys:1:Value" , secondKey ) ,
1062
- new KeyValuePair < string , string > ( "Authentication:Schemes:Bearer:SigningKeys:1:Length" , "32" ) ,
1063
- } ) . Build ( ) ;
1064
- services . AddSingleton < IConfiguration > ( config ) ;
1065
-
1066
- // Act
1067
- var builder = services . AddAuthentication ( o =>
1068
- {
1069
- o . AddScheme < TestHandler > ( "Bearer" , "Bearer" ) ;
1070
- } ) ;
1071
- builder . AddJwtBearer ( "Bearer" , o => o . UseSecurityTokenValidators = true ) ;
1072
- RegisterAuth ( builder , _ => { } ) ;
1073
- var sp = services . BuildServiceProvider ( ) ;
1074
-
1075
- // Assert
1076
- var jwtBearerOptions = sp . GetRequiredService < IOptionsMonitor < JwtBearerOptions > > ( ) . Get ( JwtBearerDefaults . AuthenticationScheme ) ;
1077
- Assert . Equal ( 2 , jwtBearerOptions . TokenValidationParameters . IssuerSigningKeys . Count ( ) ) ;
1078
- Assert . Equal ( firstKey , Convert . ToBase64String ( jwtBearerOptions . TokenValidationParameters . IssuerSigningKeys . OfType < SymmetricSecurityKey > ( ) . FirstOrDefault ( ) ? . Key ) ) ;
1079
- Assert . Equal ( secondKey , Convert . ToBase64String ( jwtBearerOptions . TokenValidationParameters . IssuerSigningKeys . OfType < SymmetricSecurityKey > ( ) . LastOrDefault ( ) ? . Key ) ) ;
1080
- }
1081
-
1082
1013
class InvalidTokenValidator : ISecurityTokenValidator
1083
1014
{
1084
1015
public InvalidTokenValidator ( )
0 commit comments