-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SASL mechanism and RabbitCrDemo example
- Loading branch information
1 parent
a8e41a2
commit 872c543
Showing
11 changed files
with
143 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
docs/examples/RabbitMQ.Next.Examples.DemoSaslAuthMechanism/ConnectionBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace RabbitMQ.Next.Examples.DemoSaslAuthMechanism; | ||
|
||
public static class ConnectionBuilderExtensions | ||
{ | ||
public static IConnectionBuilder WithRabbitCrDemoAuth(this IConnectionBuilder builder, string userName, string password) | ||
{ | ||
builder.Auth(new RabbitCrDemoAuthMechanism(userName, password)); | ||
return builder; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
docs/examples/RabbitMQ.Next.Examples.DemoSaslAuthMechanism/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace RabbitMQ.Next.Examples.DemoSaslAuthMechanism; | ||
|
||
class Program | ||
{ | ||
static async Task Main() | ||
{ | ||
Console.WriteLine("Hello World! Will try to connect RabbitMQ server with RABBIT-CR-DEMO auth mechanism."); | ||
|
||
var connection = await ConnectionBuilder.Default | ||
.Endpoint("amqp://localhost:5672/") | ||
.WithRabbitCrDemoAuth("guest", "guest") | ||
.ConnectAsync() | ||
.ConfigureAwait(false); | ||
|
||
Console.WriteLine("Connection opened"); | ||
Console.WriteLine("Press any key to close the connection"); | ||
|
||
Console.ReadKey(); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
docs/examples/RabbitMQ.Next.Examples.DemoSaslAuthMechanism/RabbitCrDemoAuthMechanism.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace RabbitMQ.Next.Examples.DemoSaslAuthMechanism; | ||
|
||
internal class RabbitCrDemoAuthMechanism : IAuthMechanism | ||
{ | ||
private readonly string username; | ||
private readonly string password; | ||
|
||
public RabbitCrDemoAuthMechanism(string username, string password) | ||
{ | ||
this.username = username; | ||
this.password = password; | ||
} | ||
|
||
public string Type => "RABBIT-CR-DEMO"; | ||
|
||
public ValueTask<ReadOnlyMemory<byte>> StartAsync() | ||
=> ValueTask.FromResult(new ReadOnlyMemory<byte>(Encoding.UTF8.GetBytes(this.username))); | ||
|
||
|
||
public ValueTask<ReadOnlyMemory<byte>> HandleChallengeAsync(ReadOnlySpan<byte> challenge) | ||
{ | ||
var serverChallenge = Encoding.UTF8.GetString(challenge); | ||
|
||
if (string.Equals("Please tell me your password", serverChallenge)) | ||
{ | ||
return ValueTask.FromResult(new ReadOnlyMemory<byte>(Encoding.UTF8.GetBytes($"My password is {this.password}"))); | ||
} | ||
|
||
throw new InvalidOperationException(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...Q.Next.Examples.DemoSaslAuthMechanism/RabbitMQ.Next.Examples.DemoSaslAuthMechanism.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\src\RabbitMQ.Next.Abstractions\RabbitMQ.Next.Abstractions.csproj" /> | ||
<ProjectReference Include="..\..\..\src\RabbitMQ.Next\RabbitMQ.Next.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters