Use TryGetValue() in TokenExtensions (#23708)

This commit is contained in:
Martin Costello 2020-07-07 06:27:59 +01:00 committed by GitHub
parent 6b2ece7e21
commit 54bd692c78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 5 deletions

View File

@ -13,8 +13,8 @@ namespace Microsoft.AspNetCore.Authentication
/// </summary> /// </summary>
public static class AuthenticationTokenExtensions public static class AuthenticationTokenExtensions
{ {
private static string TokenNamesKey = ".TokenNames"; private const string TokenNamesKey = ".TokenNames";
private static string TokenKeyPrefix = ".Token."; private const string TokenKeyPrefix = ".Token.";
/// <summary> /// <summary>
/// Stores a set of authentication tokens, after removing any old tokens. /// Stores a set of authentication tokens, after removing any old tokens.
@ -76,9 +76,8 @@ namespace Microsoft.AspNetCore.Authentication
} }
var tokenKey = TokenKeyPrefix + tokenName; var tokenKey = TokenKeyPrefix + tokenName;
return properties.Items.ContainsKey(tokenKey)
? properties.Items[tokenKey] return properties.Items.TryGetValue(tokenKey, out var value) ? value : null;
: null;
} }
public static bool UpdateTokenValue(this AuthenticationProperties properties, string tokenName, string tokenValue) public static bool UpdateTokenValue(this AuthenticationProperties properties, string tokenName, string tokenValue)