Skip to content

Commit 8cc6508

Browse files
AndyButlandkjac
authored andcommitted
Retrieve only user external logins when invalidate following removal of backoffice external user login (#19766)
* Retrieve only user external logins when invalidate following removal of backoffice external user login. * Improved variable name.
1 parent a0406b1 commit 8cc6508

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserRepository.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,26 +1264,27 @@ private Sql<ISqlContext> ApplySort(Sql<ISqlContext> sql, Expression<Func<IUser,
12641264
/// <inheritdoc />
12651265
public void InvalidateSessionsForRemovedProviders(IEnumerable<string> currentLoginProviders)
12661266
{
1267-
// Get all the user or member keys associated with the removed providers.
1267+
// Get all the user keys associated with the removed providers.
12681268
Sql<ISqlContext> idsQuery = SqlContext.Sql()
12691269
.Select<ExternalLoginDto>(x => x.UserOrMemberKey)
12701270
.From<ExternalLoginDto>()
1271+
.Where<ExternalLoginDto>(x => !x.LoginProvider.StartsWith(Constants.Security.MemberExternalAuthenticationTypePrefix)) // Only invalidate sessions relating to backoffice users, not members.
12711272
.WhereNotIn<ExternalLoginDto>(x => x.LoginProvider, currentLoginProviders);
1272-
List<Guid> userAndMemberKeysAssociatedWithRemovedProviders = Database.Fetch<Guid>(idsQuery);
1273-
if (userAndMemberKeysAssociatedWithRemovedProviders.Count == 0)
1273+
List<Guid> userKeysAssociatedWithRemovedProviders = Database.Fetch<Guid>(idsQuery);
1274+
if (userKeysAssociatedWithRemovedProviders.Count == 0)
12741275
{
12751276
return;
12761277
}
12771278

12781279
// Invalidate the security stamps on the users associated with the removed providers.
12791280
Sql<ISqlContext> updateSecurityStampsQuery = Sql()
12801281
.Update<UserDto>(u => u.Set(x => x.SecurityStampToken, "0".PadLeft(32, '0')))
1281-
.WhereIn<UserDto>(x => x.Key, userAndMemberKeysAssociatedWithRemovedProviders);
1282+
.WhereIn<UserDto>(x => x.Key, userKeysAssociatedWithRemovedProviders);
12821283
Database.Execute(updateSecurityStampsQuery);
12831284

12841285
// Delete the OpenIddict tokens for the users associated with the removed providers.
12851286
// The following is safe from SQL injection as we are dealing with GUIDs, not strings.
1286-
var userKeysForInClause = string.Join("','", userAndMemberKeysAssociatedWithRemovedProviders.Select(x => x.ToString()));
1287+
var userKeysForInClause = string.Join("','", userKeysAssociatedWithRemovedProviders.Select(x => x.ToString()));
12871288
Database.Execute("DELETE FROM umbracoOpenIddictTokens WHERE Subject IN ('" + userKeysForInClause + "')");
12881289
}
12891290

0 commit comments

Comments
 (0)