Skip to content

Commit 9dbc5ed

Browse files
fix: register MongoDB AWS authentication for Atlas IAM (driver 3.x) (#1324)
MongoDB.Driver 3.x moved MONGODB-AWS into MongoDB.Driver.Authentication.AWS and requires explicit registration. Without it, Atlas IAM connection strings fail at startup with "Unable to create an authenticator". Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 0668c09 commit 9dbc5ed

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

backend/src/Squidex.Data.MongoDb/MongoClientFactory.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Text.Json;
99
using MongoDB.Bson;
1010
using MongoDB.Driver;
11+
using MongoDB.Driver.Authentication.AWS;
1112
using Squidex.Domain.Apps.Core.Contents;
1213
using Squidex.Domain.Apps.Entities;
1314
using Squidex.Domain.Apps.Entities.Assets;
@@ -23,6 +24,8 @@ namespace Squidex;
2324

2425
public static class MongoClientFactory
2526
{
27+
private static int awsAuthenticationRegistered;
28+
2629
public static void SetupSerializer(JsonSerializerOptions jsonSerializerOptions, BsonType representation)
2730
{
2831
// Register the serializers first.
@@ -53,6 +56,11 @@ public static void SetupSerializer(JsonSerializerOptions jsonSerializerOptions,
5356

5457
public static MongoClient Create(string? connectionString, Action<MongoClientSettings>? configure = null)
5558
{
59+
if (Interlocked.Exchange(ref awsAuthenticationRegistered, 1) == 0)
60+
{
61+
MongoClientSettings.Extensions.AddAWSAuthentication();
62+
}
63+
5664
var clientSettings = MongoClientSettings.FromConnectionString(connectionString);
5765

5866
// If we really need custom config.

backend/src/Squidex.Data.MongoDb/Squidex.Data.MongoDb.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2222
</PackageReference>
2323
<PackageReference Include="MongoDB.Driver" Version="3.8.0" />
24+
<PackageReference Include="MongoDB.Driver.Authentication.AWS" Version="3.8.0" />
2425
<PackageReference Include="MongoDB.Driver.Core.Extensions.DiagnosticSources" Version="3.0.0" />
2526
<PackageReference Include="NodaTime.Serialization.SystemTextJson" Version="1.3.1" />
2627
<PackageReference Include="RefactoringEssentials" Version="5.6.0" PrivateAssets="all" />

0 commit comments

Comments
 (0)