Skip to content

Commit 352b4c8

Browse files
warwickschroederjasontaylordev
authored andcommitted
Allow multiple api scopes, or none. Add client audience config setting
1 parent f8069ef commit 352b4c8

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

src/ServiceControl/App.config

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ These settings are only here so that we can debug ServiceControl while developin
77
<appSettings>
88
<add key="ServiceControl/ForwardErrorMessages" value="false" />
99
<add key="ServiceControl/ErrorRetentionPeriod" value="10.00:00:00" />
10-
<add key="ServiceControl/RemoteInstances" value="[{&quot;api_uri&quot;:&quot;http://localhost:44444/api/&quot;}]" />
10+
<add key="ServiceControl/RemoteInstances" value="[]" />
1111
<add key="ServiceControl/HostName" value="localhost" />
1212
<add key="ServiceControl/DatabaseMaintenancePort" value="33334" />
1313
<add key="ServiceControl/AllowMessageEditing" value="true" />
@@ -24,9 +24,9 @@ These settings are only here so that we can debug ServiceControl while developin
2424

2525
<add key="ServiceControl/PersistenceType" value="RavenDB" />
2626

27-
<!-- options are any comma separated combination of NLog,Seq,Otlp -->
28-
<add key="ServiceControl/LoggingProviders" value="NLog,Seq"/>
29-
<add key="ServiceControl/SeqAddress" value="http://localhost:5341"/>
27+
<!-- options are any comma separated combination of NLog,Seq,Otlp -->
28+
<add key="ServiceControl/LoggingProviders" value="NLog,Seq"/>
29+
<add key="ServiceControl/SeqAddress" value="http://localhost:5341"/>
3030

3131
<!-- Authentication Settings (JWT with OpenID Connect) -->
3232
<!-- Uncomment and configure to enable authentication -->
@@ -40,11 +40,12 @@ These settings are only here so that we can debug ServiceControl while developin
4040
<add key="ServiceControl/Authentication.ValidateLifetime" value="true" />
4141
<add key="ServiceControl/Authentication.ValidateIssuerSigningKey" value="true" />
4242
<add key="ServiceControl/Authentication.RequireHttpsMetadata" value="true" />-->
43-
<!-- ServicePulse Authentication Settings -->
44-
<!-- <add key="ServiceControl/Authentication.ServicePulse.Enabled" value="false" />
45-
<add key="ServiceControl/Authentication.ServicePulse.ClientId" value="" />
46-
<add key="ServiceControl/Authentication.ServicePulse.Authority" value="" />
47-
<add key="ServiceControl/Authentication.ServicePulse.ApiScope" value="" /> -->
43+
44+
<!-- ServicePulse Authentication Settings -->
45+
<!--<add key="ServiceControl/Authentication.ServicePulse.ClientId" value="" />
46+
<add key="ServiceControl/Authentication.ServicePulse.Authority" value="" />
47+
<add key="ServiceControl/Authentication.ServicePulse.Audience" value="" />
48+
<add key="ServiceControl/Authentication.ServicePulse.ApiScopes" value="" />-->
4849
</appSettings>
4950
<connectionStrings>
5051
<!-- DEVS - Pick a transport connection string to match chosen transport above -->

src/ServiceControl/Authentication/AuthenticationController.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public ActionResult<AuthConfig> Configuration()
1818
Enabled = settings.OpenIdConnectSettings.Enabled,
1919
ClientId = settings.OpenIdConnectSettings.ServicePulseClientId,
2020
Authority = settings.OpenIdConnectSettings.ServicePulseAuthority,
21-
ApiScope = settings.OpenIdConnectSettings.ServicePulseApiScope
21+
Audience = settings.OpenIdConnectSettings.Audience,
22+
ApiScopes = settings.OpenIdConnectSettings.ServicePulseApiScopes
2223
};
2324

2425
return Ok(info);
@@ -30,6 +31,7 @@ public class AuthConfig
3031
public bool Enabled { get; set; }
3132
public string ClientId { get; set; }
3233
public string Authority { get; set; }
33-
public string ApiScope { get; set; }
34+
public string Audience { get; set; }
35+
public string ApiScopes { get; set; }
3436
}
3537
}

src/ServiceControl/Infrastructure/Settings/OpenIdConnectSettings.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public OpenIdConnectSettings(bool validateConfiguration)
2727
ValidateIssuerSigningKey = SettingsReader.Read(Settings.SettingsRootNamespace, "Authentication.ValidateIssuerSigningKey", true);
2828
RequireHttpsMetadata = SettingsReader.Read(Settings.SettingsRootNamespace, "Authentication.RequireHttpsMetadata", true);
2929
ServicePulseClientId = SettingsReader.Read<string>(Settings.SettingsRootNamespace, "Authentication.ServicePulse.ClientId");
30-
ServicePulseApiScope = SettingsReader.Read<string>(Settings.SettingsRootNamespace, "Authentication.ServicePulse.ApiScope");
30+
ServicePulseApiScopes = SettingsReader.Read<string>(Settings.SettingsRootNamespace, "Authentication.ServicePulse.ApiScopes");
3131
ServicePulseAuthority = SettingsReader.Read<string>(Settings.SettingsRootNamespace, "Authentication.ServicePulse.Authority");
3232

3333
if (validateConfiguration)
@@ -63,11 +63,14 @@ public OpenIdConnectSettings(bool validateConfiguration)
6363
[JsonPropertyName("servicePulseAuthority")]
6464
public string ServicePulseAuthority { get; }
6565

66+
[JsonPropertyName("servicePulseAudience")]
67+
public string ServicePulseAudience { get; }
68+
6669
[JsonPropertyName("servicePulseClientId")]
6770
public string ServicePulseClientId { get; }
6871

69-
[JsonPropertyName("servicePulseApiScope")]
70-
public string ServicePulseApiScope { get; }
72+
[JsonPropertyName("servicePulseApiScopes")]
73+
public string ServicePulseApiScopes { get; }
7174

7275
void Validate()
7376
{
@@ -129,10 +132,10 @@ void Validate()
129132
throw new Exception("Authentication.ServicePulse.ClientId is required when Authentication.ServicePulse.Enabled is true.");
130133
}
131134

132-
if (string.IsNullOrWhiteSpace(ServicePulseApiScope))
133-
{
134-
throw new Exception("Authentication.ServicePulse.ApiScope is required when Authentication.ServicePulse.Enabled is true.");
135-
}
135+
//if (string.IsNullOrWhiteSpace(ServicePulseApiScope))
136+
//{
137+
// throw new Exception("Authentication.ServicePulse.ApiScope is required when Authentication.ServicePulse.Enabled is true.");
138+
//}
136139

137140
if (ServicePulseAuthority != null && !Uri.TryCreate(ServicePulseAuthority, UriKind.Absolute, out _))
138141
{
@@ -149,7 +152,8 @@ void Validate()
149152
logger.LogInformation(" RequireHttpsMetadata: {RequireHttpsMetadata}", RequireHttpsMetadata);
150153
logger.LogInformation(" ServicePulseClientId: {ServicePulseClientId}", ServicePulseClientId);
151154
logger.LogInformation(" ServicePulseAuthority: {ServicePulseAuthority}", ServicePulseAuthority);
152-
logger.LogInformation(" ServicePulseApiScope: {ServicePulseApiScope}", ServicePulseApiScope);
155+
logger.LogInformation(" ServicePulseAudience: {ServicePulseAudience}", ServicePulseAudience);
156+
logger.LogInformation(" ServicePulseApiScopes: {ServicePulseApiScopes}", ServicePulseApiScopes);
153157
}
154158
}
155159
}

0 commit comments

Comments
 (0)