Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding oAuth #521

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/KafkaFlow.Abstractions/Configuration/SaslMechanism.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ public enum SaslMechanism

/// <summary>SCRAM-SHA-512</summary>
ScramSha512,

/// <summary>OAUTH-BEARER</summary>
OAuthBearer,
}
12 changes: 12 additions & 0 deletions src/KafkaFlow.Abstractions/Configuration/SaslOauthbearerMethod.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace KafkaFlow.Configuration
{
/// <summary>SaslOauthbearerMethod enum values</summary>
public enum SaslOauthbearerMethod
{
/// <summary>Default</summary>
Default,

/// <summary>Oidc</summary>
Oidc,
}
}
42 changes: 41 additions & 1 deletion src/KafkaFlow.Abstractions/Configuration/SecurityInformation.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace KafkaFlow.Configuration;

Check warning on line 1 in src/KafkaFlow.Abstractions/Configuration/SecurityInformation.cs

View workflow job for this annotation

GitHub Actions / build

File is required to end with a single newline character (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1518.md) [/home/runner/work/kafkaflow/kafkaflow/src/KafkaFlow.Abstractions/KafkaFlow.Abstractions.csproj]

/// <summary>
/// Represent the Kafka security information
Expand Down Expand Up @@ -209,4 +209,44 @@
/// importance: low
/// </summary>
public bool? EnableSaslOauthbearerUnsecureJwt { get; set; }
}

/// <summary>
/// Gets or sets the SaslOauthbearerMethod
///
/// default: false
/// importance: low
/// </summary>
public SaslOauthbearerMethod? SaslOauthbearerMethod { get; set; }

/// <summary>
/// Gets or sets the SaslOauthbearerClientId
///
/// default: false
/// importance: low
/// </summary>
public string SaslOauthbearerClientId { get; set; }

/// <summary>
/// Gets or sets the SaslOauthbearerClientSecret
///
/// default: false
/// importance: low
/// </summary>
public string SaslOauthbearerClientSecret { get; set; }

/// <summary>
/// Gets or sets the SaslOauthbearerTokenEndpointUrl
///
/// default: false
/// importance: low
/// </summary>
public string SaslOauthbearerTokenEndpointUrl { get; set; }

/// <summary>
/// Gets or sets the SaslOauthbearerScope
///
/// default: false
/// importance: low
/// </summary>
public string SaslOauthbearerScope { get; set; }
}

Check warning on line 252 in src/KafkaFlow.Abstractions/Configuration/SecurityInformation.cs

View workflow job for this annotation

GitHub Actions / Test deployment

16 changes: 15 additions & 1 deletion src/KafkaFlow/Extensions/ConfigurationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Confluent.Kafka;
using KafkaFlow.Configuration;
using SaslMechanism = KafkaFlow.Configuration.SaslMechanism;
using SaslOauthbearerMethod = KafkaFlow.Configuration.SaslOauthbearerMethod;
using SecurityProtocol = KafkaFlow.Configuration.SecurityProtocol;
using SslEndpointIdentificationAlgorithm = KafkaFlow.Configuration.SslEndpointIdentificationAlgorithm;

Expand All @@ -15,6 +16,14 @@ internal static class ConfigurationExtensions
SaslMechanism.Plain => Confluent.Kafka.SaslMechanism.Plain,
SaslMechanism.ScramSha256 => Confluent.Kafka.SaslMechanism.ScramSha256,
SaslMechanism.ScramSha512 => Confluent.Kafka.SaslMechanism.ScramSha512,
SaslMechanism.OAuthBearer => Confluent.Kafka.SaslMechanism.OAuthBearer,
_ => throw new ArgumentOutOfRangeException()
};

public static Confluent.Kafka.SaslOauthbearerMethod ToConfluent(this SaslOauthbearerMethod method) => method switch
{
SaslOauthbearerMethod.Default => Confluent.Kafka.SaslOauthbearerMethod.Default,
SaslOauthbearerMethod.Oidc => Confluent.Kafka.SaslOauthbearerMethod.Oidc,
_ => throw new ArgumentOutOfRangeException()
};

Expand Down Expand Up @@ -70,5 +79,10 @@ public static void ReadSecurityInformationFrom(this ClientConfig config, Cluster
config.SaslMechanism = securityInformation.SaslMechanism?.ToConfluent();
config.SaslUsername = securityInformation.SaslUsername;
config.SaslPassword = securityInformation.SaslPassword;
config.SaslOauthbearerMethod = securityInformation.SaslOauthbearerMethod?.ToConfluent();
config.SaslOauthbearerClientId = securityInformation.SaslOauthbearerClientId;
config.SaslOauthbearerClientSecret = securityInformation.SaslOauthbearerClientSecret;
config.SaslOauthbearerTokenEndpointUrl = securityInformation.SaslOauthbearerTokenEndpointUrl;
config.SaslOauthbearerScope = securityInformation.SaslOauthbearerScope;
}
}
}
Loading