@@ -36,6 +36,53 @@ public void PostConfigure_AddsClientIdToValidAudiences()
3636
3737 [ Fact ]
3838 public async Task PostConfigure_ConfiguresForCloudFoundry ( )
39+ {
40+ const string vcapServices = """
41+ {
42+ "p-identity": [
43+ {
44+ "label": "p-identity",
45+ "provider": null,
46+ "plan": "steeltoe",
47+ "name": "mySSOService",
48+ "tags": [],
49+ "instance_guid": "ea8b8ac0-ce85-4726-8b39-d1b2eb55b45b",
50+ "instance_name": "mySSOService",
51+ "binding_guid": "be94e8e7-9246-49af-935f-5390ff10ac23",
52+ "binding_name": null,
53+ "credentials": {
54+ "auth_domain": "https://steeltoe.uaa.sys.cf-app.com",
55+ "grant_types": [ "client_credentials" ],
56+ "client_secret": "dd2c82e1-aa99-4eaf-9871-2eb7412b79bb",
57+ "client_id": "4e6f8e34-f42b-440e-a042-f2b13c1d5bed"
58+ },
59+ "syslog_drain_url": null,
60+ "volume_mounts": []
61+ }]
62+ }
63+ """ ;
64+
65+ using var servicesScope = new EnvironmentVariableScope ( "VCAP_SERVICES" , vcapServices ) ;
66+ IConfiguration configuration = new ConfigurationBuilder ( ) . AddCloudFoundryServiceBindings ( ) . Build ( ) ;
67+ var services = new ServiceCollection ( ) ;
68+ services . AddSingleton ( configuration ) ;
69+ services . AddAuthentication ( ) . AddJwtBearer ( ) . ConfigureJwtBearerForCloudFoundry ( ) ;
70+
71+ await using ServiceProvider serviceProvider = services . BuildServiceProvider ( true ) ;
72+ var optionsMonitor = serviceProvider . GetRequiredService < IOptionsMonitor < JwtBearerOptions > > ( ) ;
73+ JwtBearerOptions options = optionsMonitor . Get ( JwtBearerDefaults . AuthenticationScheme ) ;
74+
75+ options . Authority . Should ( ) . Be ( "https://steeltoe.uaa.sys.cf-app.com" ) ;
76+ options . MetadataAddress . Should ( ) . Be ( "https://steeltoe.uaa.sys.cf-app.com/.well-known/openid-configuration" ) ;
77+ options . RequireHttpsMetadata . Should ( ) . BeTrue ( ) ;
78+ options . TokenValidationParameters . ValidIssuer . Should ( ) . Be ( "https://steeltoe.uaa.sys.cf-app.com/oauth/token" ) ;
79+ options . TokenValidationParameters . ValidIssuers . Should ( ) . BeEmpty ( ) ;
80+ options . TokenValidationParameters . IssuerSigningKeyResolver . Should ( ) . NotBeNull ( ) ;
81+ options . TokenValidationParameters . ValidAudiences . Should ( ) . Contain ( "4e6f8e34-f42b-440e-a042-f2b13c1d5bed" ) ;
82+ }
83+
84+ [ Fact ]
85+ public async Task PostConfigure_ConfiguresForCloudFoundry_AllowMultipleIssuers ( )
3986 {
4087 const string vcapServices = """
4188 {
@@ -62,6 +109,7 @@ public async Task PostConfigure_ConfiguresForCloudFoundry()
62109 }
63110 """ ;
64111
112+ using var applicationScope = new EnvironmentVariableScope ( "VCAP_APPLICATION" , "{}" ) ;
65113 using var servicesScope = new EnvironmentVariableScope ( "VCAP_SERVICES" , vcapServices ) ;
66114 IConfiguration configuration = new ConfigurationBuilder ( ) . AddCloudFoundryServiceBindings ( ) . Build ( ) ;
67115 var services = new ServiceCollection ( ) ;
@@ -75,7 +123,10 @@ public async Task PostConfigure_ConfiguresForCloudFoundry()
75123 options . Authority . Should ( ) . Be ( "https://steeltoe.login.sys.cf-app.com" ) ;
76124 options . MetadataAddress . Should ( ) . Be ( "https://steeltoe.login.sys.cf-app.com/.well-known/openid-configuration" ) ;
77125 options . RequireHttpsMetadata . Should ( ) . BeTrue ( ) ;
78- options . TokenValidationParameters . ValidIssuer . Should ( ) . Be ( "https://steeltoe.login.sys.cf-app.com/oauth/token" ) ;
126+ options . TokenValidationParameters . ValidIssuer . Should ( ) . BeNull ( ) ;
127+ options . TokenValidationParameters . ValidIssuers . Should ( ) . Contain ( "https://steeltoe.login.sys.cf-app.com/oauth/token" ) . And
128+ . Contain ( "https://steeltoe.uaa.sys.cf-app.com/oauth/token" ) ;
129+
79130 options . TokenValidationParameters . IssuerSigningKeyResolver . Should ( ) . NotBeNull ( ) ;
80131 options . TokenValidationParameters . ValidAudiences . Should ( ) . Contain ( "4e6f8e34-f42b-440e-a042-f2b13c1d5bed" ) ;
81132 }
0 commit comments