Skip to content

Commit

Permalink
Merge pull request #101 from dlmelendez/rel/7.0
Browse files Browse the repository at this point in the history
Rel/7.0
  • Loading branch information
dlmelendez authored Nov 9, 2022
2 parents ee6cabf + 0643074 commit bc4ba07
Show file tree
Hide file tree
Showing 22 changed files with 328 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Copyright>Copyright © 2022 David Melendez, MIT License</Copyright>
<AssemblyTitle>Azure Table Storage Provider for ASP.NET Identity Core Models</AssemblyTitle>
<Authors>David Melendez</Authors>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net6.0;net7.0</TargetFrameworks>
<LangVersion>9.0</LangVersion>
<AssemblyName>ElCamino.AspNetCore.Identity.AzureTable.Model</AssemblyName>
<AssemblyOriginatorKeyFile>../../tools/Key.snk</AssemblyOriginatorKeyFile>
Expand All @@ -22,7 +22,7 @@
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/dlmelendez/identityazuretable.git</RepositoryUrl>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>6.2</Version>
<Version>7.0</Version>
<PackageProjectUrl>https://dlmelendez.github.io/identityazuretable</PackageProjectUrl>
<!--<DebugType>Full</DebugType>-->
<!-- DebugType Full is needed for test code coverage, but .nuget symbols doesn't like it-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Copyright>Copyright © 2022 David Melendez, MIT License</Copyright>
<AssemblyTitle>Azure Table Storage Provider for ASP.NET Identity Core</AssemblyTitle>
<Authors>David Melendez</Authors>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net6.0;net7.0</TargetFrameworks>
<LangVersion>10.0</LangVersion>
<AssemblyName>ElCamino.AspNetCore.Identity.AzureTable</AssemblyName>
<AssemblyOriginatorKeyFile>../../tools/Key.snk</AssemblyOriginatorKeyFile>
Expand All @@ -21,7 +21,7 @@
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/dlmelendez/identityazuretable.git</RepositoryUrl>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>6.2</Version>
<Version>7.0</Version>
<PackageProjectUrl>https://dlmelendez.github.io/identityazuretable</PackageProjectUrl>
<!--<DebugType>Full</DebugType>-->
<!-- DebugType Full is needed for test code coverage, but .nuget symbols doesn't like it-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,18 @@ public virtual string GenerateRowKeyIdentityUserLogin(string loginProvider, stri
return string.Format(FormatterIdentityUserLogin, hash);
}

public double KeyVersion => 6.2;
public double KeyVersion => 7.0;

public abstract string ConvertKeyToHash(string input);

/// <summary>
/// Left only for backwards compat for older frameworks.
/// </summary>
/// <param name="shaHash"></param>
/// <param name="input"></param>
/// <param name="encoding"></param>
/// <param name="hashHexLength"></param>
/// <returns></returns>
protected virtual string GetHash(HashAlgorithm shaHash, string input, Encoding encoding, int hashHexLength)
{
// Convert the input string to a byte array and compute the hash.
Expand All @@ -168,5 +176,14 @@ protected virtual string GetHash(HashAlgorithm shaHash, string input, Encoding e
// Return the hexadecimal string.
return sBuilder.ToString();
}

#if NET6_0_OR_GREATER
protected static string FormatHashedData(byte[] hashedData)
{
// Convert the input string to a byte array and compute the hash.
return Convert.ToHexString(hashedData).ToLowerInvariant();
}
#endif

}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
// MIT License Copyright 2020 (c) David Melendez. All rights reserved. See License.txt in the project root for license information.

using System;
using System.Security.Cryptography;
using System.Text;

namespace ElCamino.AspNetCore.Identity.AzureTable.Helpers
{
public class DefaultKeyHelper : BaseKeyHelper
{
public override string ConvertKeyToHash(string input)
#if NET6_0_OR_GREATER

public sealed override string ConvertKeyToHash(string input)
{
if (input != null)
{
byte[] data = SHA1.HashData(Encoding.Unicode.GetBytes(input));
return FormatHashedData(data);
}
return null;
}
#else
public sealed override string ConvertKeyToHash(string input)
{
if (input != null)
{
Expand All @@ -16,5 +29,6 @@ public override string ConvertKeyToHash(string input)
}
return null;
}
#endif
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// MIT License Copyright 2020 (c) David Melendez. All rights reserved. See License.txt in the project root for license information.

using System;
using System.Security.Cryptography;
using System.Text;

Expand All @@ -10,7 +11,21 @@ namespace ElCamino.AspNetCore.Identity.AzureTable.Helpers
/// </summary>
public class SHA256KeyHelper : BaseKeyHelper
{
public override string ConvertKeyToHash(string input)

#if NET6_0_OR_GREATER
public sealed override string ConvertKeyToHash(string input)
{
if (input != null)
{
byte[] data = SHA256.HashData(Encoding.UTF8.GetBytes(input));
return FormatHashedData(data);
}
return null;
}

#else

public sealed override string ConvertKeyToHash(string input)
{
if (input != null)
{
Expand All @@ -19,6 +34,7 @@ public override string ConvertKeyToHash(string input)
}
return null;
}
#endif

public override string GenerateRowKeyUserId(string plainUserId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,37 @@ public static class IdentityAzureTableBuilderExtensions
{
/// <summary>
/// Use this to load and configure the Identity Azure Tables into the aspnet identity pipeline.
/// Note: <see cref="IdentityBuilder.AddRoles{TRole}"/> prior to calling this methiod in the pipeline if you need Roles functionality, otherwise the RoleStore will not be loaded.
/// Note: <see cref="IdentityBuilder.AddRoles{TRole}"/> prior to calling this method in the pipeline if you need Roles functionality, otherwise the RoleStore will not be loaded.
/// </summary>
/// <typeparam name="TContext">Use or extend <see cref="IdentityCloudContext"/></typeparam>
/// <param name="builder"><see cref="IdentityBuilder"/> aspnet identity pipeline</param>
/// <param name="configAction"><see cref="IdentityConfiguration"/></param>
/// <param name="keyHelper">Use <see cref="DefaultKeyHelper"/> that uses SHA1, <see cref="SHA256KeyHelper"/> or a custom keyhelper that implements <see cref="IKeyHelper"/> </param>
/// <param name="keyHelper">Use <see cref="DefaultKeyHelper"/> that uses SHA1, <see cref="SHA256KeyHelper"/> or a custom keyhelper that implements <see cref="IKeyHelper"/> </param>
/// <returns><see cref="IdentityBuilder"/></returns>
public static IdentityBuilder AddAzureTableStores<TContext>(this IdentityBuilder builder, Func<IdentityConfiguration> configAction,
IKeyHelper keyHelper = null)
where TContext : IdentityCloudContext
{
return builder.AddAzureTableStores<TContext>(_ => configAction(), keyHelper);
}

/// <summary>
/// Use this to load and configure the Identity Azure Tables into the aspnet identity pipeline.
/// Note: <see cref="IdentityBuilder.AddRoles{TRole}"/> prior to calling this method in the pipeline if you need Roles functionality, otherwise the RoleStore will not be loaded.
/// </summary>
/// <typeparam name="TContext">Use or extend <see cref="IdentityCloudContext"/></typeparam>
/// <param name="builder"><see cref="IdentityBuilder"/> aspnet identity pipeline</param>
/// <param name="configAction"><see cref="IdentityConfiguration"/></param>
/// <param name="keyHelper">Use <see cref="DefaultKeyHelper"/> that uses SHA1, <see cref="SHA256KeyHelper"/> or a custom keyhelper that implements <see cref="IKeyHelper"/> </param>
/// <returns><see cref="IdentityBuilder"/></returns>
public static IdentityBuilder AddAzureTableStores<TContext>(this IdentityBuilder builder, Func<IServiceProvider, IdentityConfiguration> configAction,
IKeyHelper keyHelper = null)
where TContext : IdentityCloudContext
{

builder.Services.AddSingleton<IKeyHelper>(keyHelper ?? new DefaultKeyHelper());

builder.Services.AddSingleton<IdentityConfiguration>(new Func<IServiceProvider, IdentityConfiguration>(p => configAction()));
builder.Services.AddSingleton<IdentityConfiguration>(configAction);

Type contextType = typeof(TContext);
builder.Services.AddSingleton(contextType, contextType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Copyright>Copyright © 2022 David Melendez, MIT License</Copyright>
<AssemblyTitle>Azure Table Storage Extensions</AssemblyTitle>
<Authors>David Melendez</Authors>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net6.0;net7.0</TargetFrameworks>
<LangVersion>10.0</LangVersion>
<AssemblyName>ElCamino.Azure.Data.Tables</AssemblyName>
<AssemblyOriginatorKeyFile>../../tools/Key.snk</AssemblyOriginatorKeyFile>
Expand All @@ -20,7 +20,7 @@
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/dlmelendez/identityazuretable.git</RepositoryUrl>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>6.2</Version>
<Version>7.0</Version>
<PackageProjectUrl>https://dlmelendez.github.io/identityazuretable</PackageProjectUrl>
<!--<DebugType>Full</DebugType>-->
<!-- DebugType Full is needed for test code coverage, but .nuget symbols doesn't like it-->
Expand Down
4 changes: 2 additions & 2 deletions src/ElCamino.Azure.Data.Tables/TableClientExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ public static async Task<T> GetEntityOrDefaultAsync<T>(
TableQuery.GenerateFilterCondition(nameof(TableEntity.RowKey), QueryComparisons.Equal, rowKey));

var page = await table.QueryAsync<T>(filter: filterString, maxPerPage: 1, select: select, cancellationToken)
.AsPages(continuationToken: null, pageSizeHint: 1).FirstOrDefaultAsync().ConfigureAwait(false);
return page?.Values.FirstOrDefault();
.AsPages(continuationToken: null, pageSizeHint: 1).FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false);
return page?.Values.Count > 0 ? page.Values[0] : null;
}

/// <summary>
Expand Down
9 changes: 8 additions & 1 deletion src/ElCamino.Azure.Data.Tables/TableQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,22 @@ public static string GenerateFilterConditionForBinary(
string operation,
byte[] givenValue)
{
string hash;

#if NET6_0_OR_GREATER
hash = Convert.ToHexString(givenValue).ToLowerInvariant();
#else
StringBuilder sb = new StringBuilder();

foreach (byte b in givenValue)
{
sb.AppendFormat("{0:x2}", b);
}

return GenerateFilterCondition(propertyName, operation, sb.ToString(), EdmType.Binary);
hash = sb.ToString();
#endif

return GenerateFilterCondition(propertyName, operation, hash, EdmType.Binary);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>9.0</LangVersion>
<TargetFramework>net7.0</TargetFramework>
<LangVersion>10.0</LangVersion>
<AssemblyName>ElCamino.Identity.AzureTable.DataUtility</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>ElCamino.Identity.AzureTable.DataUtility</PackageId>
Expand All @@ -11,7 +11,7 @@
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<EnableDefaultContentItems>false</EnableDefaultContentItems>
<Version>6.2</Version>
<Version>7.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -43,12 +43,12 @@
<ItemGroup>
<PackageReference Include="Azure.Data.Tables" Version="12.6.1" />
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="6.0.8" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="6.0.8" />
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="7.0.0" />

<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<AssemblyTitle>Web Project Templates for Azure Table Storage Provider for ASP.NET Identity Core</AssemblyTitle>
<Authors>David Melendez</Authors>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<Title>ElCamino.AspNetCore.Identity.AzureTable.Templates</Title>
<PackageId>ElCamino.AspNetCore.Identity.AzureTable.Templates</PackageId>
<Description>ASP.NET Core Web Template Pack for ElCamino Identity Azure Table Storage</Description>
Expand All @@ -19,7 +19,7 @@
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/dlmelendez/identityazuretable.git</RepositoryUrl>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>6.2</Version>
<Version>7.0</Version>
<PackageProjectUrl>https://dlmelendez.github.io/identityazuretable</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
Expand Down
2 changes: 1 addition & 1 deletion templates/templates/StarterWebMvc-CSharp/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"IdentityAzureTable": {
"IdentityConfiguration": {
"TablePrefix": "v6",
"TablePrefix": "v7",
"StorageConnectionString": "UseDevelopmentStorage=true;",
"IndexTableName": "AspNetIndex",
"RoleTableName": "AspNetRoles",
Expand Down
44 changes: 44 additions & 0 deletions templates/templates/StarterWebMvc-CSharp/libman.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"version": "1.0",
"defaultProvider": "cdnjs",
"libraries": [
{
"provider": "unpkg",
"library": "jquery-validation@1.19.5",
"destination": "wwwroot/lib/jquery-validation/",
"files": [
"dist/jquery.validate.js",
"dist/jquery.validate.min.js"
]
},
{
"provider": "unpkg",
"library": "bootstrap@5.2.2",
"destination": "wwwroot/lib/bootstrap/",
"files": [
"dist/css/bootstrap.css",
"dist/css/bootstrap.css.map",
"dist/css/bootstrap.min.css",
"dist/css/bootstrap.min.css.map",
"dist/js/bootstrap.bundle.js",
"dist/js/bootstrap.bundle.js.map",
"dist/js/bootstrap.bundle.min.js",
"dist/js/bootstrap.bundle.min.js.map",
"dist/js/bootstrap.js",
"dist/js/bootstrap.js.map",
"dist/js/bootstrap.min.js",
"dist/js/bootstrap.min.js.map"
]
},
{
"provider": "unpkg",
"library": "jquery@3.6.1",
"destination": "wwwroot/lib/jquery/",
"files": [
"dist/jquery.js",
"dist/jquery.min.js",
"dist/jquery.min.map"
]
}
]
}
12 changes: 6 additions & 6 deletions templates/templates/StarterWebMvc-CSharp/samplemvccore.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>aspnet-samplemvccore-FECFB455-D41D-47DD-B371-2C0F71AC101F</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ElCamino.AspNetCore.Identity.AzureTable" Version="6.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="6.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.1" />
<PackageReference Include="ElCamino.AspNetCore.Identity.AzureTable" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="7.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"IdentityAzureTable": {
"IdentityConfiguration": {
"TablePrefix": "v6",
"TablePrefix": "v7",
"StorageConnectionString": "UseDevelopmentStorage=true;",
"IndexTableName": "AspNetIndex",
"RoleTableName": "AspNetRoles",
Expand Down
Loading

0 comments on commit bc4ba07

Please sign in to comment.