Skip to content

Commit 5383cae

Browse files
committed
fix: AddIdentity instead AddIdentityCore
1 parent 33abaaa commit 5383cae

3 files changed

Lines changed: 11 additions & 13 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ After execute this steps you will be all set to use the Identity in your Applica
7373
### Configuring JWT
7474
If you want to generate JSON Web Tokens in your application you need to add the JWT configuration in `ConfigureServices` method of your `startup.cs`
7575
```csharp
76-
services.AddJwtConfiguration(Configuration);
76+
services.AddJwtConfiguration(Configuration)
77+
.AddNetDevPackIdentity<IdentityUser>();
7778
```
7879

7980
Set your `appsettings.json` file with this values:

src/NetDevPack.Identity/JwtBuilderExtensions.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22
using Microsoft.AspNetCore.Builder;
33
using Microsoft.AspNetCore.Identity;
44
using Microsoft.EntityFrameworkCore;
5-
using Microsoft.Extensions.DependencyInjection;
6-
using Microsoft.Extensions.DependencyInjection.Extensions;
75
using NetDevPack.Identity.Data;
86
using NetDevPack.Identity.Interfaces;
97
using NetDevPack.Identity.Jwt;
10-
using NetDevPack.Security.Jwt.Core;
118
using NetDevPack.Security.Jwt.Core.Interfaces;
129

1310
namespace Microsoft.Extensions.DependencyInjection;
@@ -32,23 +29,24 @@ public static IJwksBuilder AddNetDevPackIdentity(this IServiceCollection service
3229
services.AddScoped<IJwtBuilder, JwtBuilderInject<IdentityUser, string>>();
3330
return services.AddHttpContextAccessor().AddJwksManager();
3431
}
35-
32+
3633
public static IdentityBuilder AddIdentityConfiguration(this IServiceCollection services)
3734
{
3835
if (services == null) throw new ArgumentException(nameof(services));
3936
services.AddNetDevPackIdentity();
4037

41-
return services.AddIdentityCore<IdentityUser>()
42-
.AddRoles<IdentityRole>()
43-
.AddEntityFrameworkStores<NetDevPackAppDbContext>()
44-
.AddDefaultTokenProviders();
38+
return services
39+
.AddIdentity<IdentityUser, IdentityRole>()
40+
.AddEntityFrameworkStores<NetDevPackAppDbContext>()
41+
.AddDefaultTokenProviders();
4542
}
4643

4744
public static IdentityBuilder AddDefaultIdentity(this IServiceCollection services, Action<IdentityOptions> options = null)
4845
{
4946
if (services == null) throw new ArgumentException(nameof(services));
5047
services.AddNetDevPackIdentity<IdentityUser>();
51-
return services.AddIdentityCore<IdentityUser>(options)
48+
return services
49+
.AddIdentity<IdentityUser, IdentityRole>()
5250
.AddDefaultTokenProviders();
5351
}
5452

@@ -57,7 +55,7 @@ public static IdentityBuilder AddCustomIdentity<TIdentityUser>(this IServiceColl
5755
{
5856
if (services == null) throw new ArgumentException(nameof(services));
5957

60-
return services.AddIdentityCore<TIdentityUser>(options)
58+
return services.AddIdentity<TIdentityUser, IdentityRole>(options)
6159
.AddDefaultTokenProviders();
6260
}
6361

@@ -67,7 +65,7 @@ public static IdentityBuilder AddCustomIdentity<TIdentityUser, TKey>(this IServi
6765
{
6866
if (services == null) throw new ArgumentException(nameof(services));
6967
services.AddNetDevPackIdentity<TIdentityUser, TKey>();
70-
return services.AddIdentityCore<TIdentityUser>(options)
68+
return services.AddIdentity<TIdentityUser, IdentityRole<TKey>>(options)
7169
.AddDefaultTokenProviders();
7270
}
7371

src/NetDevPack.Identity/NetDevPack.Identity.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
<ItemGroup>
5353
<PackageReference Include="NetDevPack.Security.Jwt.AspNetCore" Version="6.0.5" />
5454
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.17.0" />
55-
5655
</ItemGroup>
5756

5857

0 commit comments

Comments
 (0)