Skip to content

Commit 249c738

Browse files
committed
Updates
1 parent 6a830c1 commit 249c738

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

src/Identity/Core/src/SignInManager.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,18 +304,20 @@ public virtual async Task SignInWithClaimsAsync(TUser user, AuthenticationProper
304304
{
305305
userPrincipal.Identities.First().AddClaim(claim);
306306
}
307+
308+
authenticationProperties ??= new AuthenticationProperties();
307309
await Context.SignInAsync(AuthenticationScheme,
308310
userPrincipal,
309-
authenticationProperties ?? new AuthenticationProperties());
311+
authenticationProperties);
310312

311313
// This is useful for updating claims immediately when hitting MapIdentityApi's /account/info endpoint with cookies.
312314
Context.User = userPrincipal;
313315

314-
_metrics?.SignInUserPrincipal(typeof(TUser).FullName!, AuthenticationScheme);
316+
_metrics?.SignInUserPrincipal(typeof(TUser).FullName!, AuthenticationScheme, authenticationProperties.IsPersistent);
315317
}
316318
catch (Exception ex)
317319
{
318-
_metrics?.SignInUserPrincipal(typeof(TUser).FullName!, AuthenticationScheme, ex);
320+
_metrics?.SignInUserPrincipal(typeof(TUser).FullName!, AuthenticationScheme, isPersistent: null, ex);
319321
throw;
320322
}
321323
}

src/Identity/Core/src/SignInManagerMetrics.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public SignInManagerMetrics(IMeterFactory meterFactory)
3333
_rememberTwoFactorClientCounter = _meter.CreateCounter<long>(RememberTwoFactorCounterName, "count", "The number of two factor clients remembered.");
3434
_forgetTwoFactorCounter = _meter.CreateCounter<long>(ForgetTwoFactorCounterName, "count", "The number of two factor clients forgotten.");
3535
_checkPasswordCounter = _meter.CreateCounter<long>(CheckPasswordCounterName, "count", "The number of check password attempts. Checks that the account is in a state that can log in and that the password is valid using the UserManager.CheckPasswordAsync method.");
36-
_signInUserPrincipalCounter = _meter.CreateCounter<long>(SignInUserPrincipalCounterName, "count", "The number of user principals signed in.");
37-
_signOutUserPrincipalCounter = _meter.CreateCounter<long>(SignOutUserPrincipalCounterName, "count", "The number of user principals signed out.");
36+
_signInUserPrincipalCounter = _meter.CreateCounter<long>(SignInUserPrincipalCounterName, "count", "The number of calls to sign in user principals.");
37+
_signOutUserPrincipalCounter = _meter.CreateCounter<long>(SignOutUserPrincipalCounterName, "count", "The number of calls to sign out user principals.");
3838
}
3939

4040
internal void CheckPasswordSignIn(string userType, SignInResult? result, Exception? exception = null)
@@ -67,17 +67,14 @@ internal void AuthenticateSignIn(string userType, string authenticationScheme, S
6767
{ "aspnetcore.identity.authentication_scheme", authenticationScheme },
6868
{ "aspnetcore.identity.sign_in.type", GetSignInType(signInType) },
6969
};
70-
if (isPersistent != null)
71-
{
72-
tags.Add("aspnetcore.identity.sign_in.is_persistent", isPersistent.Value);
73-
}
70+
AddIsPersistent(ref tags, isPersistent);
7471
AddSignInResult(ref tags, result);
7572
AddExceptionTags(ref tags, exception);
7673

7774
_authenticateCounter.Add(1, tags);
7875
}
7976

80-
internal void SignInUserPrincipal(string userType, string authenticationScheme, Exception? exception = null)
77+
internal void SignInUserPrincipal(string userType, string authenticationScheme, bool? isPersistent, Exception? exception = null)
8178
{
8279
if (!_signInUserPrincipalCounter.Enabled)
8380
{
@@ -89,6 +86,7 @@ internal void SignInUserPrincipal(string userType, string authenticationScheme,
8986
{ "aspnetcore.identity.user_type", userType },
9087
{ "aspnetcore.identity.authentication_scheme", authenticationScheme },
9188
};
89+
AddIsPersistent(ref tags, isPersistent);
9290
AddExceptionTags(ref tags, exception);
9391

9492
_signInUserPrincipalCounter.Add(1, tags);
@@ -150,6 +148,14 @@ public void Dispose()
150148
_meter.Dispose();
151149
}
152150

151+
private static void AddIsPersistent(ref TagList tags, bool? isPersistent)
152+
{
153+
if (isPersistent != null)
154+
{
155+
tags.Add("aspnetcore.identity.sign_in.is_persistent", isPersistent.Value);
156+
}
157+
}
158+
153159
private static void AddSignInResult(ref TagList tags, SignInResult? result)
154160
{
155161
if (result != null)

src/Identity/test/Identity.Test/SignInManagerTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ public async Task ExternalSignInRequiresVerificationIfNotBypassed(bool bypass)
405405
[
406406
KeyValuePair.Create<string, object>("aspnetcore.identity.user_type", "Microsoft.AspNetCore.Identity.Test.PocoUser"),
407407
KeyValuePair.Create<string, object>("aspnetcore.identity.authentication_scheme", "Identity.Application"),
408+
KeyValuePair.Create<string, object>("aspnetcore.identity.sign_in.is_persistent", false),
408409
]));
409410
}
410411
else
@@ -471,6 +472,7 @@ public async Task CanPasskeySignIn()
471472
[
472473
KeyValuePair.Create<string, object>("aspnetcore.identity.user_type", "Microsoft.AspNetCore.Identity.Test.PocoUser"),
473474
KeyValuePair.Create<string, object>("aspnetcore.identity.authentication_scheme", "Identity.Application"),
475+
KeyValuePair.Create<string, object>("aspnetcore.identity.sign_in.is_persistent", false),
474476
]));
475477
}
476478

0 commit comments

Comments
 (0)