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