Update TotpSecurityStampBasedTokenProvider.cs

Add line breaks before return statement.
Use string interpolation instead of string concatenation.
Hyphenate the documentation.
This commit is contained in:
Jonathan 2020-06-10 12:12:09 +02:00 committed by GitHub
parent 9b8cd29087
commit 103a305c25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 5 deletions

View File

@ -5,7 +5,7 @@ using System.Threading.Tasks;
namespace Microsoft.AspNetCore.Identity namespace Microsoft.AspNetCore.Identity
{ {
/// <summary> /// <summary>
/// Represents a token provider that generates time based codes using the user's security stamp. /// Represents a token provider that generates time-based codes using the user's security stamp.
/// </summary> /// </summary>
/// <typeparam name="TUser">The type encapsulating a user.</typeparam> /// <typeparam name="TUser">The type encapsulating a user.</typeparam>
public abstract class TotpSecurityStampBasedTokenProvider<TUser> : IUserTwoFactorTokenProvider<TUser> public abstract class TotpSecurityStampBasedTokenProvider<TUser> : IUserTwoFactorTokenProvider<TUser>
@ -38,6 +38,7 @@ namespace Microsoft.AspNetCore.Identity
} }
var token = await manager.CreateSecurityTokenAsync(user); var token = await manager.CreateSecurityTokenAsync(user);
var modifier = await GetUserModifierAsync(purpose, manager, user); var modifier = await GetUserModifierAsync(purpose, manager, user);
return Rfc6238AuthenticationService.GenerateCode(token, modifier).ToString("D6", CultureInfo.InvariantCulture); return Rfc6238AuthenticationService.GenerateCode(token, modifier).ToString("D6", CultureInfo.InvariantCulture);
} }
@ -67,6 +68,7 @@ namespace Microsoft.AspNetCore.Identity
} }
var securityToken = await manager.CreateSecurityTokenAsync(user); var securityToken = await manager.CreateSecurityTokenAsync(user);
var modifier = await GetUserModifierAsync(purpose, manager, user); var modifier = await GetUserModifierAsync(purpose, manager, user);
return securityToken != null && Rfc6238AuthenticationService.ValidateCode(securityToken, code, modifier); return securityToken != null && Rfc6238AuthenticationService.ValidateCode(securityToken, code, modifier);
} }
@ -87,11 +89,12 @@ namespace Microsoft.AspNetCore.Identity
throw new ArgumentNullException(nameof(manager)); throw new ArgumentNullException(nameof(manager));
} }
var userId = await manager.GetUserIdAsync(user); var userId = await manager.GetUserIdAsync(user);
return "Totp:" + purpose + ":" + userId;
return $"{Totp}:{purpose}:{userId}";
} }
/// <summary> /// <summary>
/// Returns a flag indicating whether the token provider can generate a token suitable for two factor authentication token for /// Returns a flag indicating whether the token provider can generate a token suitable for two-factor authentication token for
/// the specified <paramref name="user"/>. /// the specified <paramref name="user"/>.
/// </summary> /// </summary>
/// <param name="manager">The <see cref="UserManager{TUser}"/> that can be used to retrieve user properties.</param> /// <param name="manager">The <see cref="UserManager{TUser}"/> that can be used to retrieve user properties.</param>
@ -99,8 +102,8 @@ namespace Microsoft.AspNetCore.Identity
/// <returns> /// <returns>
/// The <see cref="Task"/> that represents the asynchronous operation, containing the a flag indicating if a two /// The <see cref="Task"/> that represents the asynchronous operation, containing the a flag indicating if a two
/// factor token could be generated by this provider for the specified <paramref name="user"/>. /// factor token could be generated by this provider for the specified <paramref name="user"/>.
/// The task will return true if a two factor authentication token could be generated, otherwise false. /// The task will return true if a two-factor authentication token could be generated, otherwise false.
/// </returns> /// </returns>
public abstract Task<bool> CanGenerateTwoFactorTokenAsync(UserManager<TUser> manager, TUser user); public abstract Task<bool> CanGenerateTwoFactorTokenAsync(UserManager<TUser> manager, TUser user);
} }
} }