Skip to content

Commit

Permalink
Make OIDC token validation configurable (defaults to true)
Browse files Browse the repository at this point in the history
  • Loading branch information
kbeaugrand committed Jun 28, 2022
1 parent eec2057 commit 25e6b30
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/AzureIoTHub.Portal/Server/ConfigHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public abstract class ConfigHandler
internal const string OIDCMetadataUrlKey = "OIDC:MetadataUrl";
internal const string OIDCClientIdKey = "OIDC:ClientId";
internal const string OIDCApiClientIdKey = "OIDC:ApiClientId";
internal const string OIDCValidateIssuerKey = "OIDC:ValidateIssuer";
internal const string OIDCValidateAudienceKey = "OIDC:ValidateAudience";
internal const string OIDCValidateLifetimeKey = "OIDC:ValidateLifetime";
internal const string OIDCValidateIssuerSigningKeyKey = "OIDC:ValidateIssuerSigningKey";

internal const string IsLoRaFeatureEnabledKey = "LoRaFeature:Enabled";

Expand Down Expand Up @@ -67,6 +71,14 @@ internal static ConfigHandler Create(IWebHostEnvironment env, IConfiguration con

internal abstract string OIDCAuthority { get; }

internal abstract bool OIDCValidateIssuer { get; }

internal abstract bool OIDCValidateAudience { get; }

internal abstract bool OIDCValidateLifetime { get; }

internal abstract bool OIDCValidateIssuerSigningKey { get; }

internal abstract bool IsLoRaEnabled { get; }

internal abstract string StorageAccountBlobContainerName { get; }
Expand Down
8 changes: 8 additions & 0 deletions src/AzureIoTHub.Portal/Server/DevelopmentConfigHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ internal DevelopmentConfigHandler(IConfiguration config)

internal override string OIDCApiClientId => this.config[OIDCApiClientIdKey];

internal override bool OIDCValidateIssuer => this.config.GetValue(OIDCValidateIssuerKey, true);

internal override bool OIDCValidateAudience => this.config.GetValue(OIDCValidateAudienceKey, true);

internal override bool OIDCValidateLifetime => this.config.GetValue(OIDCValidateLifetimeKey, true);

internal override bool OIDCValidateIssuerSigningKey => this.config.GetValue(OIDCValidateIssuerSigningKeyKey, true);

internal override bool IsLoRaEnabled => bool.Parse(this.config[IsLoRaFeatureEnabledKey] ?? "true");

internal override string StorageAccountBlobContainerName => this.config[StorageAccountBlobContainerNameKey];
Expand Down
8 changes: 8 additions & 0 deletions src/AzureIoTHub.Portal/Server/ProductionConfigHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ internal ProductionConfigHandler(IConfiguration config)

internal override string OIDCApiClientId => this.config[OIDCApiClientIdKey];

internal override bool OIDCValidateIssuer => this.config.GetValue(OIDCValidateIssuerKey, true);

internal override bool OIDCValidateAudience => this.config.GetValue(OIDCValidateAudienceKey, true);

internal override bool OIDCValidateLifetime => this.config.GetValue(OIDCValidateLifetimeKey, true);

internal override bool OIDCValidateIssuerSigningKey => this.config.GetValue(OIDCValidateIssuerSigningKeyKey, true);

internal override bool IsLoRaEnabled => bool.Parse(this.config[IsLoRaFeatureEnabledKey] ?? "true");

internal override string StorageAccountBlobContainerName => this.config[StorageAccountBlobContainerNameKey];
Expand Down
8 changes: 4 additions & 4 deletions src/AzureIoTHub.Portal/Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ public void ConfigureServices(IServiceCollection services)
opts.MetadataAddress = configuration.OIDCMetadataUrl;
opts.Audience = configuration.OIDCApiClientId;

opts.TokenValidationParameters.ValidateIssuer = true;
opts.TokenValidationParameters.ValidateAudience = true;
opts.TokenValidationParameters.ValidateLifetime = true;
opts.TokenValidationParameters.ValidateIssuerSigningKey = true;
opts.TokenValidationParameters.ValidateIssuer = configuration.OIDCValidateIssuer;
opts.TokenValidationParameters.ValidateAudience = configuration.OIDCValidateAudience;
opts.TokenValidationParameters.ValidateLifetime = configuration.OIDCValidateLifetime;
opts.TokenValidationParameters.ValidateIssuerSigningKey = configuration.OIDCValidateIssuerSigningKey;
});

_ = services.AddSingleton(configuration);
Expand Down

0 comments on commit 25e6b30

Please sign in to comment.