Skip to content

Commit

Permalink
feat: add oauth
Browse files Browse the repository at this point in the history
feat: add oauth
  • Loading branch information
diogoabcosta89 committed Apr 3, 2024
1 parent 9871063 commit 4d2a0e5
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 2 deletions.
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
Expand Up @@ -209,4 +209,44 @@ public class SecurityInformation
/// 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;
}
}
}

0 comments on commit 4d2a0e5

Please sign in to comment.