public async Task <Guid> CreateAsync(OAuthClient oAuthClient, CancellationToken ct) { var clientId = Guid.NewGuid(); var newOAuthClient = new OAuthClient { Id = clientId, ClientId = oAuthClient.ClientId, ClientSecret = PasswordUtils.ToPasswordHash(oAuthClient.ClientSecret), RedirectUriPattern = oAuthClient.RedirectUriPattern, IsLocked = oAuthClient.IsLocked, IsDeleted = oAuthClient.IsDeleted, CreateDateTime = DateTime.UtcNow, Scopes = oAuthClient.Scopes?.Select(x => new OAuthClientScope { Id = Guid.NewGuid(), OAuthClientId = clientId, Value = x.Value }).ToList() }; var entry = await _storage.AddAsync(newOAuthClient, ct); await _storage.SaveChangesAsync(ct); return(entry.Entity.Id); }
public async Task <Guid> RegisterAsync( string country, string surname, string name, string login, string email, string phone, string password, string ipAddress, string userAgent, CancellationToken ct) { var profile = new Profile { Surname = surname, Name = name }; profile.Id = await _profilesService.CreateAsync(profile, ct); var passwordHash = PasswordUtils.ToPasswordHash(password); await _registrationIdentityService.CreateLoginIdentityAsync(profile.Id, login, passwordHash, ct); await _registrationIdentityService.CreateEmailIdentityAsync(profile.Id, email, passwordHash, ct); await _registrationIdentityService.CreatePhoneIdentityAsync(profile.Id, phone, passwordHash, ct); await _emailConfirmationService.SendMessageAsync(email, ipAddress, userAgent, ct); var tokenId = await _phoneConfirmationService.SendMessageAsync(country, phone, ipAddress, userAgent, ct); return(tokenId); }
public Task SetPasswordAsync(Models.Identity identity, string password, CancellationToken ct) { identity.PasswordHash = PasswordUtils.ToPasswordHash(password); identity.ModifyDateTime = DateTime.UtcNow; _storage.Update(identity); return(_storage.SaveChangesAsync(ct)); }
public async Task ChangePasswordByProfileIdAsync(Guid profileId, string newPassword, CancellationToken ct) { var passwordHash = PasswordUtils.ToPasswordHash(newPassword); await _storage.Identities .Where(x => x.ProfileId == profileId && IdentityTypeExtensions.TypesWithPassword.Contains(x.Type)) .ForEachAsync(x => { x.PasswordHash = passwordHash; x.ModifyDateTime = DateTime.UtcNow; }, ct); await _storage.SaveChangesAsync(ct); }
public Task UpdateAsync(OAuthClient oldOAuthClient, OAuthClient oAuthClient, CancellationToken ct) { oldOAuthClient.ClientId = oAuthClient.ClientId; oldOAuthClient.ClientSecret = PasswordUtils.ToPasswordHash(oAuthClient.ClientSecret); oldOAuthClient.RedirectUriPattern = oAuthClient.RedirectUriPattern; oldOAuthClient.IsLocked = oAuthClient.IsLocked; oldOAuthClient.IsDeleted = oAuthClient.IsDeleted; oldOAuthClient.ModifyDateTime = DateTime.UtcNow; oldOAuthClient.Scopes = oAuthClient.Scopes .Select(s => new OAuthClientScope { Id = oldOAuthClient.Id, OAuthClientId = s.OAuthClientId, Value = s.Value }) .ToList(); _storage.Update(oldOAuthClient); return(_storage.SaveChangesAsync(ct)); }
public static bool IsCorrectSecret(this OAuthClient oAuthClient, TokenRequest request) { return(request.grant_type != GrandType.AuthorizationCode || PasswordUtils.IsVerifiedPassword(request.client_secret, oAuthClient.ClientSecret)); }
public bool IsPasswordCorrect(Models.Identity identity, string password) { return(PasswordUtils.IsVerifiedPassword(password, identity.PasswordHash)); }