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
{
/// <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>
/// <typeparam name="TUser">The type encapsulating a user.</typeparam>
public abstract class TotpSecurityStampBasedTokenProvider<TUser> : IUserTwoFactorTokenProvider<TUser>
@ -38,6 +38,7 @@ namespace Microsoft.AspNetCore.Identity
}
var token = await manager.CreateSecurityTokenAsync(user);
var modifier = await GetUserModifierAsync(purpose, manager, user);
return Rfc6238AuthenticationService.GenerateCode(token, modifier).ToString("D6", CultureInfo.InvariantCulture);
}
@ -67,6 +68,7 @@ namespace Microsoft.AspNetCore.Identity
}
var securityToken = await manager.CreateSecurityTokenAsync(user);
var modifier = await GetUserModifierAsync(purpose, manager, user);
return securityToken != null && Rfc6238AuthenticationService.ValidateCode(securityToken, code, modifier);
}
@ -87,11 +89,12 @@ namespace Microsoft.AspNetCore.Identity
throw new ArgumentNullException(nameof(manager));
}
var userId = await manager.GetUserIdAsync(user);
return "Totp:" + purpose + ":" + userId;
return $"{Totp}:{purpose}:{userId}";
}
/// <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"/>.
/// </summary>
/// <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>
/// 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"/>.
/// 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>
public abstract Task<bool> CanGenerateTwoFactorTokenAsync(UserManager<TUser> manager, TUser user);
}
}
}