public async Task <ResourceOwner?> AuthenticateResourceOwner( string login, string password, CancellationToken cancellationToken) { var confirmationCode = await _confirmationCodeStore.Get(password, login, cancellationToken).ConfigureAwait(false); if (confirmationCode == null || confirmationCode.Subject != login) { return(null); } if (confirmationCode.IssueAt.AddSeconds(confirmationCode.ExpiresIn) <= DateTimeOffset.UtcNow) { return(null); } var resourceOwner = await _resourceOwnerRepository.GetResourceOwnerByClaim( OpenIdClaimTypes.PhoneNumber, login, cancellationToken) .ConfigureAwait(false); if (resourceOwner != null) { await _confirmationCodeStore.Remove(password, resourceOwner.Subject !, cancellationToken) .ConfigureAwait(false); } return(resourceOwner); }
public async Task <ResourceOwner> AuthenticateResourceOwnerAsync(string login, string password) { if (string.IsNullOrWhiteSpace(login)) { throw new ArgumentNullException(nameof(login)); } if (string.IsNullOrWhiteSpace(password)) { throw new ArgumentNullException(nameof(password)); } var resourceOwner = await _resourceOwnerRepository.GetResourceOwnerByClaim(Core.Jwt.Constants.StandardResourceOwnerClaimNames.PhoneNumber, login).ConfigureAwait(false); if (resourceOwner == null) { return(null); } var confirmationCode = await _confirmationCodeStore.Get(password).ConfigureAwait(false); if (confirmationCode == null || confirmationCode.Subject != resourceOwner.Claims.First(c => c.Type == Core.Jwt.Constants.StandardResourceOwnerClaimNames.PhoneNumber).Value) { return(null); } if (confirmationCode.IssueAt.AddSeconds(confirmationCode.ExpiresIn) <= DateTime.UtcNow) { return(null); } await _confirmationCodeStore.Remove(password).ConfigureAwait(false); return(resourceOwner); }
public async Task <bool> Execute(string code, string subject, CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(code)) { return(false); } var confirmationCode = await _confirmationCodeStore.Get(code, subject, cancellationToken).ConfigureAwait(false); if (confirmationCode == null) { return(false); } var expirationDateTime = confirmationCode.IssueAt.AddSeconds(confirmationCode.ExpiresIn); if (DateTimeOffset.UtcNow < expirationDateTime) { return(true); } await _confirmationCodeStore.Remove(code, subject, cancellationToken).ConfigureAwait(false); return(false); }
private async Task <string> GetCode() { var random = new Random(); var number = random.Next(100000, 999999); if (await _confirmationCodeStore.Get(number.ToString()) != null) { return(await GetCode()); } return(number.ToString()); }
private async Task <string> GetCode(string subject, CancellationToken cancellationToken) { var random = new Random(); var number = random.Next(100000, 999999); if (await _confirmationCodeStore.Get(number.ToString(), subject, cancellationToken).ConfigureAwait(false) != null) { return(await GetCode(subject, cancellationToken).ConfigureAwait(false)); } return(number.ToString()); }
public async Task <bool> Execute(string code) { if (string.IsNullOrWhiteSpace(code)) { throw new ArgumentNullException(nameof(code)); } var confirmationCode = await _confirmationCodeStore.Get(code); if (confirmationCode == null) { return(false); } var expirationDateTime = confirmationCode.IssueAt.AddSeconds(confirmationCode.ExpiresIn); return(DateTime.UtcNow < expirationDateTime); }