Skip to content

Commit

Permalink
Allow TokenCredentials to be passed in (supporting Managed Identities…
Browse files Browse the repository at this point in the history
… instead of Shared Access Keys)
  • Loading branch information
MatthewSteeples committed Dec 23, 2022
1 parent bc4ba07 commit 9d98fcd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// MIT License Copyright 2020 (c) David Melendez. All rights reserved. See License.txt in the project root for license information.


using Azure.Core;

namespace ElCamino.AspNetCore.Identity.AzureTable.Model
{
public class IdentityConfiguration
Expand All @@ -15,5 +17,7 @@ public class IdentityConfiguration

public string RoleTableName { get; set; }

public TokenCredential TokenCredential { get; set; }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Data.Tables" Version="12.6.1" />
<PackageReference Include="Azure.Data.Tables" Version="12.7.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,19 @@ public IdentityCloudContext(IdentityConfiguration config)
protected virtual void Initialize(IdentityConfiguration config)
{
_config = config;

if (string.IsNullOrEmpty(_config.StorageConnectionString))
{
throw new ArgumentNullException(nameof(config.StorageConnectionString));
}

_client = new TableServiceClient(_config.StorageConnectionString);

if (config.TokenCredential != null)
{
_client = new TableServiceClient(_client.Uri, config.TokenCredential);
}

_indexTable = _client.GetTableClient(FormatTableNameWithPrefix(!string.IsNullOrWhiteSpace(_config.IndexTableName) ? _config.IndexTableName : TableConstants.TableNames.IndexTable));
_roleTable = _client.GetTableClient(FormatTableNameWithPrefix(!string.IsNullOrWhiteSpace(_config.RoleTableName) ? _config.RoleTableName : TableConstants.TableNames.RolesTable));
_userTable = _client.GetTableClient(FormatTableNameWithPrefix(!string.IsNullOrWhiteSpace(_config.UserTableName) ? _config.UserTableName : TableConstants.TableNames.UsersTable));
Expand Down

0 comments on commit 9d98fcd

Please sign in to comment.