Skip to content

Commit 54bd692

Browse files
Use TryGetValue() in TokenExtensions (#23708)
1 parent 6b2ece7 commit 54bd692

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/Http/Authentication.Abstractions/src/TokenExtensions.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ namespace Microsoft.AspNetCore.Authentication
1313
/// </summary>
1414
public static class AuthenticationTokenExtensions
1515
{
16-
private static string TokenNamesKey = ".TokenNames";
17-
private static string TokenKeyPrefix = ".Token.";
16+
private const string TokenNamesKey = ".TokenNames";
17+
private const string TokenKeyPrefix = ".Token.";
1818

1919
/// <summary>
2020
/// Stores a set of authentication tokens, after removing any old tokens.
@@ -76,9 +76,8 @@ public static void StoreTokens(this AuthenticationProperties properties, IEnumer
7676
}
7777

7878
var tokenKey = TokenKeyPrefix + tokenName;
79-
return properties.Items.ContainsKey(tokenKey)
80-
? properties.Items[tokenKey]
81-
: null;
79+
80+
return properties.Items.TryGetValue(tokenKey, out var value) ? value : null;
8281
}
8382

8483
public static bool UpdateTokenValue(this AuthenticationProperties properties, string tokenName, string tokenValue)

0 commit comments

Comments
 (0)