Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitebb0398

Browse files
Merge pull request#64014 from dotnet/backport/pr-63981-to-release/10.0
[release/10.0] Allow `UserStore` to update passkey name
1 parent9fc1da3 commitebb0398

File tree

13 files changed

+437
-117
lines changed

13 files changed

+437
-117
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespaceMicrosoft.AspNetCore.Identity.EntityFrameworkCore;
5+
6+
internalstaticclassIdentityUserPasskeyExtensions
7+
{
8+
extension<TKey>(IdentityUserPasskey<TKey> passkey)
9+
where TKey:IEquatable<TKey>
10+
{
11+
publicvoidUpdateFromUserPasskeyInfo(UserPasskeyInfopasskeyInfo)
12+
{
13+
passkey.Data.Name=passkeyInfo.Name;
14+
passkey.Data.SignCount=passkeyInfo.SignCount;
15+
passkey.Data.IsBackedUp=passkeyInfo.IsBackedUp;
16+
passkey.Data.IsUserVerified=passkeyInfo.IsUserVerified;
17+
}
18+
19+
publicUserPasskeyInfoToUserPasskeyInfo()
20+
=>new(
21+
passkey.CredentialId,
22+
passkey.Data.PublicKey,
23+
passkey.Data.CreatedAt,
24+
passkey.Data.SignCount,
25+
passkey.Data.Transports,
26+
passkey.Data.IsUserVerified,
27+
passkey.Data.IsBackupEligible,
28+
passkey.Data.IsBackedUp,
29+
passkey.Data.AttestationObject,
30+
passkey.Data.ClientDataJson)
31+
{
32+
Name=passkey.Data.Name
33+
};
34+
}
35+
}

‎src/Identity/EntityFrameworkCore/src/UserOnlyStore.cs‎

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -625,10 +625,7 @@ public virtual async Task AddOrUpdatePasskeyAsync(TUser user, UserPasskeyInfo pa
625625
varuserPasskey=awaitFindUserPasskeyByIdAsync(passkey.CredentialId,cancellationToken).ConfigureAwait(false);
626626
if(userPasskey!=null)
627627
{
628-
userPasskey.Data.Name=passkey.Name;
629-
userPasskey.Data.SignCount=passkey.SignCount;
630-
userPasskey.Data.IsBackedUp=passkey.IsBackedUp;
631-
userPasskey.Data.IsUserVerified=passkey.IsUserVerified;
628+
userPasskey.UpdateFromUserPasskeyInfo(passkey);
632629
UserPasskeys.Update(userPasskey);
633630
}
634631
else
@@ -655,20 +652,7 @@ public virtual async Task<IList<UserPasskeyInfo>> GetPasskeysAsync(TUser user, C
655652
varuserId=user.Id;
656653
varpasskeys=awaitUserPasskeys
657654
.Where(p=>p.UserId.Equals(userId))
658-
.Select(p=>newUserPasskeyInfo(
659-
p.CredentialId,
660-
p.Data.PublicKey,
661-
p.Data.CreatedAt,
662-
p.Data.SignCount,
663-
p.Data.Transports,
664-
p.Data.IsUserVerified,
665-
p.Data.IsBackupEligible,
666-
p.Data.IsBackedUp,
667-
p.Data.AttestationObject,
668-
p.Data.ClientDataJson)
669-
{
670-
Name=p.Data.Name,
671-
})
655+
.Select(p=>p.ToUserPasskeyInfo())
672656
.ToListAsync(cancellationToken)
673657
.ConfigureAwait(false);
674658

@@ -708,26 +692,10 @@ public virtual async Task<IList<UserPasskeyInfo>> GetPasskeysAsync(TUser user, C
708692
cancellationToken.ThrowIfCancellationRequested();
709693
ThrowIfDisposed();
710694
ArgumentNullException.ThrowIfNull(user);
695+
ArgumentNullException.ThrowIfNull(credentialId);
711696

712697
varpasskey=awaitFindUserPasskeyAsync(user.Id,credentialId,cancellationToken).ConfigureAwait(false);
713-
if(passkey!=null)
714-
{
715-
returnnewUserPasskeyInfo(
716-
passkey.CredentialId,
717-
passkey.Data.PublicKey,
718-
passkey.Data.CreatedAt,
719-
passkey.Data.SignCount,
720-
passkey.Data.Transports,
721-
passkey.Data.IsUserVerified,
722-
passkey.Data.IsBackupEligible,
723-
passkey.Data.IsBackedUp,
724-
passkey.Data.AttestationObject,
725-
passkey.Data.ClientDataJson)
726-
{
727-
Name=passkey.Data.Name,
728-
};
729-
}
730-
returnnull;
698+
returnpasskey?.ToUserPasskeyInfo();
731699
}
732700

733701
/// <summary>

‎src/Identity/EntityFrameworkCore/src/UserStore.cs‎

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -770,9 +770,7 @@ public virtual async Task AddOrUpdatePasskeyAsync(TUser user, UserPasskeyInfo pa
770770
varuserPasskey=awaitFindUserPasskeyByIdAsync(passkey.CredentialId,cancellationToken).ConfigureAwait(false);
771771
if(userPasskey!=null)
772772
{
773-
userPasskey.Data.SignCount=passkey.SignCount;
774-
userPasskey.Data.IsBackedUp=passkey.IsBackedUp;
775-
userPasskey.Data.IsUserVerified=passkey.IsUserVerified;
773+
userPasskey.UpdateFromUserPasskeyInfo(passkey);
776774
UserPasskeys.Update(userPasskey);
777775
}
778776
else
@@ -799,20 +797,7 @@ public virtual async Task<IList<UserPasskeyInfo>> GetPasskeysAsync(TUser user, C
799797
varuserId=user.Id;
800798
varpasskeys=awaitUserPasskeys
801799
.Where(p=>p.UserId.Equals(userId))
802-
.Select(p=>newUserPasskeyInfo(
803-
p.CredentialId,
804-
p.Data.PublicKey,
805-
p.Data.CreatedAt,
806-
p.Data.SignCount,
807-
p.Data.Transports,
808-
p.Data.IsUserVerified,
809-
p.Data.IsBackupEligible,
810-
p.Data.IsBackedUp,
811-
p.Data.AttestationObject,
812-
p.Data.ClientDataJson)
813-
{
814-
Name=p.Data.Name
815-
})
800+
.Select(p=>p.ToUserPasskeyInfo())
816801
.ToListAsync(cancellationToken)
817802
.ConfigureAwait(false);
818803

@@ -851,27 +836,11 @@ public virtual async Task<IList<UserPasskeyInfo>> GetPasskeysAsync(TUser user, C
851836
{
852837
cancellationToken.ThrowIfCancellationRequested();
853838
ThrowIfDisposed();
839+
ArgumentNullException.ThrowIfNull(user);
854840
ArgumentNullException.ThrowIfNull(credentialId);
855841

856842
varpasskey=awaitFindUserPasskeyAsync(user.Id,credentialId,cancellationToken).ConfigureAwait(false);
857-
if(passkey!=null)
858-
{
859-
returnnewUserPasskeyInfo(
860-
passkey.CredentialId,
861-
passkey.Data.PublicKey,
862-
passkey.Data.CreatedAt,
863-
passkey.Data.SignCount,
864-
passkey.Data.Transports,
865-
passkey.Data.IsUserVerified,
866-
passkey.Data.IsBackupEligible,
867-
passkey.Data.IsBackedUp,
868-
passkey.Data.AttestationObject,
869-
passkey.Data.ClientDataJson)
870-
{
871-
Name=passkey.Data.Name
872-
};
873-
}
874-
returnnull;
843+
returnpasskey?.ToUserPasskeyInfo();
875844
}
876845

877846
/// <summary>

‎src/Identity/EntityFrameworkCore/test/EF.InMemory.Test/InMemoryContext.cs‎

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,31 @@
33

44
usingSystem.Data.Common;
55
usingMicrosoft.EntityFrameworkCore;
6+
usingMicrosoft.Extensions.DependencyInjection;
67

78
namespaceMicrosoft.AspNetCore.Identity.EntityFrameworkCore.InMemory.Test;
89

910
publicclassInMemoryContext:
1011
InMemoryContext<IdentityUser,IdentityRole,string>
1112
{
12-
privateInMemoryContext(DbConnectionconnection):base(connection)
13+
privateInMemoryContext(DbConnectionconnection,IServiceProviderserviceProvider):base(connection,serviceProvider)
1314
{}
1415

15-
publicstaticnewInMemoryContextCreate(DbConnectionconnection)
16-
=>Initialize(newInMemoryContext(connection));
16+
publicstaticnewInMemoryContextCreate(DbConnectionconnection,IServiceCollectionservices=null)
17+
{
18+
services=ConfigureDbServices(services);
19+
returnInitialize(newInMemoryContext(connection,services.BuildServiceProvider()));
20+
}
21+
22+
publicstaticIServiceCollectionConfigureDbServices(IServiceCollectionservices=null)
23+
{
24+
services??=newServiceCollection();
25+
services.Configure<IdentityOptions>(options=>
26+
{
27+
options.Stores.SchemaVersion=IdentitySchemaVersions.Version3;
28+
});
29+
returnservices;
30+
}
1731

1832
publicstaticTContextInitialize<TContext>(TContextcontext)whereTContext:DbContext
1933
{
@@ -28,17 +42,25 @@ public class InMemoryContext<TUser> :
2842
whereTUser:IdentityUser
2943
{
3044
privatereadonlyDbConnection_connection;
45+
privatereadonlyIServiceProvider_serviceProvider;
3146

32-
privateInMemoryContext(DbConnectionconnection)
47+
privateInMemoryContext(DbConnectionconnection,IServiceProviderserviceProvider)
3348
{
3449
_connection=connection;
50+
_serviceProvider=serviceProvider;
3551
}
3652

37-
publicstaticInMemoryContext<TUser>Create(DbConnectionconnection)
38-
=>InMemoryContext.Initialize(newInMemoryContext<TUser>(connection));
53+
publicstaticInMemoryContext<TUser>Create(DbConnectionconnection,IServiceCollectionservices=null)
54+
{
55+
services=InMemoryContext.ConfigureDbServices(services);
56+
returnInMemoryContext.Initialize(newInMemoryContext<TUser>(connection,services.BuildServiceProvider()));
57+
}
3958

4059
protectedoverridevoidOnConfiguring(DbContextOptionsBuilderoptionsBuilder)
41-
=>optionsBuilder.UseSqlite(_connection);
60+
{
61+
optionsBuilder.UseSqlite(_connection);
62+
optionsBuilder.UseApplicationServiceProvider(_serviceProvider);
63+
}
4264
}
4365

4466
publicclassInMemoryContext<TUser,TRole,TKey>:IdentityDbContext<TUser,TRole,TKey>
@@ -47,17 +69,25 @@ public class InMemoryContext<TUser, TRole, TKey> : IdentityDbContext<TUser, TRol
4769
whereTKey:IEquatable<TKey>
4870
{
4971
privatereadonlyDbConnection_connection;
72+
privatereadonlyIServiceProvider_serviceProvider;
5073

51-
protectedInMemoryContext(DbConnectionconnection)
74+
protectedInMemoryContext(DbConnectionconnection,IServiceProviderserviceProvider)
5275
{
5376
_connection=connection;
77+
_serviceProvider=serviceProvider;
5478
}
5579

56-
publicstaticInMemoryContext<TUser,TRole,TKey>Create(DbConnectionconnection)
57-
=>InMemoryContext.Initialize(newInMemoryContext<TUser,TRole,TKey>(connection));
80+
publicstaticInMemoryContext<TUser,TRole,TKey>Create(DbConnectionconnection,IServiceCollectionservices=null)
81+
{
82+
services=InMemoryContext.ConfigureDbServices(services);
83+
returnInMemoryContext.Initialize(newInMemoryContext<TUser,TRole,TKey>(connection,services.BuildServiceProvider()));
84+
}
5885

5986
protectedoverridevoidOnConfiguring(DbContextOptionsBuilderoptionsBuilder)
60-
=>optionsBuilder.UseSqlite(_connection);
87+
{
88+
optionsBuilder.UseSqlite(_connection);
89+
optionsBuilder.UseApplicationServiceProvider(_serviceProvider);
90+
}
6191
}
6292

6393
publicabstractclassInMemoryContext<TUser,TRole,TKey,TUserClaim,TUserRole,TUserLogin,TRoleClaim,TUserToken>:

‎src/Identity/EntityFrameworkCore/test/EF.InMemory.Test/InMemoryStoreWithGenericsTest.cs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ public InMemoryEFUserStoreTestWithGenerics(InMemoryDatabaseFixture fixture)
2424

2525
varservices=newServiceCollection();
2626
services.AddHttpContextAccessor();
27+
services.Configure<IdentityOptions>(options=>
28+
{
29+
options.Stores.SchemaVersion=IdentitySchemaVersions.Version3;
30+
});
2731
services.AddDbContext<InMemoryContextWithGenerics>(
2832
options=>options
2933
.UseSqlite(_fixture.Connection)

‎src/Identity/EntityFrameworkCore/test/EF.Test/DbUtil.cs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ public static IServiceCollection ConfigureDbServices<TContext>(
3030
.UseSqlite(connection);
3131
});
3232

33+
services.Configure<IdentityOptions>(options=>
34+
{
35+
options.Stores.SchemaVersion=IdentitySchemaVersions.Version3;
36+
});
37+
3338
returnservices;
3439
}
3540

‎src/Identity/EntityFrameworkCore/test/EF.Test/SqlStoreTestBase.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ protected virtual void SetupAddIdentity(IServiceCollection services)
3737
options.Password.RequireNonAlphanumeric=false;
3838
options.Password.RequireUppercase=false;
3939
options.User.AllowedUserNameCharacters=null;
40+
options.Stores.SchemaVersion=IdentitySchemaVersions.Version3;
4041
})
4142
.AddRoles<TRole>()
4243
.AddDefaultTokenProviders()

‎src/Identity/EntityFrameworkCore/test/EF.Test/UserStoreEncryptPersonalDataTest.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ protected override void SetupAddIdentity(IServiceCollection services)
2525
options.Password.RequireNonAlphanumeric=false;
2626
options.Password.RequireUppercase=false;
2727
options.User.AllowedUserNameCharacters=null;
28+
options.Stores.SchemaVersion=IdentitySchemaVersions.Version3;
2829
})
2930
.AddDefaultTokenProviders()
3031
.AddEntityFrameworkStores<TestDbContext>()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp