Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.
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
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -85,5 +86,13 @@ public class CosmosDbPartitionedStorageOptions
/// The default for backwards compatibility is 255 <see cref="CosmosDbKeyEscape.MaxKeyLength"/>.
/// </value>
public bool CompatibilityMode { get; set; } = true;

/// <summary>
/// Gets or sets the token credential for Cosmos DB.
/// </summary>
/// <value>
/// The token credential for Cosmos DB.
/// </value>
public TokenCredential TokenCredential { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Rest.ClientRuntime" Version="2.3.21" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.15.1" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.32.2" />
<PackageReference Include="Microsoft.Azure.Storage.Blob" Version="9.4.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ public void ConstructorValidation()
CosmosDbEndpoint = null,
}));

// No Auth Key. Should throw.
// No Auth Key or TokenCredential. Should throw.
Assert.Throws<ArgumentException>(() => new CosmosDbPartitionedStorage(new CosmosDbPartitionedStorageOptions()
{
CosmosDbEndpoint = "CosmosDbEndpoint",
AuthKey = null,
TokenCredential = null
}));

// No Database Id. Should throw.
Expand Down