diff --git a/libraries/Microsoft.Bot.Builder.Azure/CosmosDbPartitionedStorage.cs b/libraries/Microsoft.Bot.Builder.Azure/CosmosDbPartitionedStorage.cs
index 1b16268962..a8bc9b7fe7 100644
--- a/libraries/Microsoft.Bot.Builder.Azure/CosmosDbPartitionedStorage.cs
+++ b/libraries/Microsoft.Bot.Builder.Azure/CosmosDbPartitionedStorage.cs
@@ -53,9 +53,9 @@ public CosmosDbPartitionedStorage(CosmosDbPartitionedStorageOptions cosmosDbStor
throw new ArgumentException($"Service EndPoint for CosmosDB is required.", nameof(cosmosDbStorageOptions));
}
- if (string.IsNullOrEmpty(cosmosDbStorageOptions.AuthKey))
+ if (string.IsNullOrEmpty(cosmosDbStorageOptions.AuthKey) && cosmosDbStorageOptions.TokenCredential == null)
{
- throw new ArgumentException("AuthKey for CosmosDB is required.", nameof(cosmosDbStorageOptions));
+ throw new ArgumentException("AuthKey or TokenCredential for CosmosDB is required.", nameof(cosmosDbStorageOptions));
}
if (string.IsNullOrEmpty(cosmosDbStorageOptions.DatabaseId))
@@ -388,10 +388,20 @@ private async Task InitializeAsync()
var assemblyName = this.GetType().Assembly.GetName();
cosmosClientOptions.ApplicationName = string.Concat(assemblyName.Name, " ", assemblyName.Version.ToString());
- _client = new CosmosClient(
+ if (_cosmosDbStorageOptions.TokenCredential != null)
+ {
+ _client = new CosmosClient(
+ _cosmosDbStorageOptions.CosmosDbEndpoint,
+ _cosmosDbStorageOptions.TokenCredential,
+ cosmosClientOptions);
+ }
+ else
+ {
+ _client = new CosmosClient(
_cosmosDbStorageOptions.CosmosDbEndpoint,
_cosmosDbStorageOptions.AuthKey,
cosmosClientOptions);
+ }
}
if (_container == null)
diff --git a/libraries/Microsoft.Bot.Builder.Azure/CosmosDbPartitionedStorageOptions.cs b/libraries/Microsoft.Bot.Builder.Azure/CosmosDbPartitionedStorageOptions.cs
index e1a7dfaec3..8a996bf14b 100644
--- a/libraries/Microsoft.Bot.Builder.Azure/CosmosDbPartitionedStorageOptions.cs
+++ b/libraries/Microsoft.Bot.Builder.Azure/CosmosDbPartitionedStorageOptions.cs
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
+using Azure.Core;
using Microsoft.Azure.Cosmos;
namespace Microsoft.Bot.Builder.Azure
@@ -85,5 +86,13 @@ public class CosmosDbPartitionedStorageOptions
/// The default for backwards compatibility is 255 .
///
public bool CompatibilityMode { get; set; } = true;
+
+ ///
+ /// Gets or sets the token credential for Cosmos DB.
+ ///
+ ///
+ /// The token credential for Cosmos DB.
+ ///
+ public TokenCredential TokenCredential { get; set; }
}
}
diff --git a/libraries/Microsoft.Bot.Builder.Azure/Microsoft.Bot.Builder.Azure.csproj b/libraries/Microsoft.Bot.Builder.Azure/Microsoft.Bot.Builder.Azure.csproj
index efbcab3799..8a58f7438b 100644
--- a/libraries/Microsoft.Bot.Builder.Azure/Microsoft.Bot.Builder.Azure.csproj
+++ b/libraries/Microsoft.Bot.Builder.Azure/Microsoft.Bot.Builder.Azure.csproj
@@ -36,7 +36,7 @@
-
+
diff --git a/tests/Microsoft.Bot.Builder.Azure.Tests/CosmosDbPartitionedStorageTests.cs b/tests/Microsoft.Bot.Builder.Azure.Tests/CosmosDbPartitionedStorageTests.cs
index a72cd51bad..f16b197a5c 100644
--- a/tests/Microsoft.Bot.Builder.Azure.Tests/CosmosDbPartitionedStorageTests.cs
+++ b/tests/Microsoft.Bot.Builder.Azure.Tests/CosmosDbPartitionedStorageTests.cs
@@ -44,11 +44,12 @@ public void ConstructorValidation()
CosmosDbEndpoint = null,
}));
- // No Auth Key. Should throw.
+ // No Auth Key or TokenCredential. Should throw.
Assert.Throws(() => new CosmosDbPartitionedStorage(new CosmosDbPartitionedStorageOptions()
{
CosmosDbEndpoint = "CosmosDbEndpoint",
AuthKey = null,
+ TokenCredential = null
}));
// No Database Id. Should throw.