public Task UpdateAsync(Consent consent) { using (var scope = TransactionScopeFactory.CreateReadCommitted()) { var item = dataModel.Consents.SingleOrDefault(x => x.Subject == consent.Subject && x.ClientId == consent.ClientId); if (consent.Scopes == null || !consent.Scopes.Any()) { if (item != null) { item.Delete(); } } else { if (item == null) { item = dataModel.Consents.Create(); item.Id = Guid.NewGuid(); item.Subject = consent.Subject; item.ClientId = consent.ClientId; } item.Scopes = StringifyScopes(consent.Scopes); } scope.Complete(); } return Task.FromResult(0); }
public async Task UpdateAsync(Models.Consent consent) { var item = await context.Consents .Where(x => x.SubjectId == consent.Subject && x.ClientId == consent.ClientId) .FirstOrDefaultAsync(); if (item == null) { item = new Entities.Consent { SubjectId = consent.Subject, ClientId = consent.ClientId }; context.Consents.Add(item); } if (consent.Scopes == null || !consent.Scopes.Any()) { context.Consents.Remove(item); } item.Scopes = consent.Scopes.StringifyScopes(); await context.SaveChangesAsync(); }
/// <summary> /// Persists the subject's consent. /// </summary> /// <param name="consent">The consent.</param> /// <returns>A task.</returns> public async Task UpdateAsync(Consent consent) { using (var ctx = _dbContextFactory.Create()) { var item = await ctx.IdnConsents.FindAsync(consent.Subject, consent.ClientId); if (item == null) { item = new SqlIdnConsent { Subject = consent.Subject, ClientId = consent.ClientId }; ctx.IdnConsents.Add(item); } if (consent.Scopes == null || !consent.Scopes.Any()) { ctx.IdnConsents.Remove(item); } item.Scopes = StringifyScopes(consent.Scopes); await ctx.SaveChangesAsync(); } }
public async Task UpdateAsync(Consent consent) { using (var scope = DataAccessScope.CreateReadCommitted()) { var item = dataModel.Consents.SingleOrDefault(x => x.Subject == consent.Subject && x.ClientId == consent.ClientId); if (consent.Scopes == null || !consent.Scopes.Any()) { item?.Delete(); } else { if (item == null) { item = dataModel.Consents.Create(); item.Id = Guid.NewGuid(); item.Subject = consent.Subject; item.ClientId = consent.ClientId; } item.Scopes = StringifyScopes(consent.Scopes); } await scope.CompleteAsync(); } }
public async Task UpdateAsync(Consent consent) { var result = await Collection.ReplaceOneAsync( Filter.ById(ConsentSerializer.GetId(consent.ClientId, consent.Subject)), _serializer.Serialize(consent), PerformUpsert).ConfigureAwait(false); Log.Debug(result.ToString); }
internal static StoredConsent ToDbFormat(Consent consent) { return new StoredConsent { Id = "consents/" + consent.Subject + "/" + consent.ClientId, ClientId = consent.ClientId, Subject = consent.Subject, Scopes = consent.Scopes }; }
public async Task RevokesAGivenConsent(NpgsqlConsentStore store, Consent consent) { // Given await store.UpdateAsync(consent); // When await store.RevokeAsync(consent.Subject, consent.ClientId); // Then var fromDb = await store.LoadAsync(consent.Subject, consent.ClientId); fromDb.ShouldBe(null); }
public async Task InsertsConsentIfItDoesNotExist(NpgsqlConsentStore store, Consent consent) { // Given var before = await store.LoadAsync(consent.Subject, consent.ClientId); before.ShouldBe(null); // When await store.UpdateAsync(consent); // Then var fromDb = await store.LoadAsync(consent.Subject, consent.ClientId); fromDb.ShouldNotBe(null); fromDb.ClientId.ShouldBe(consent.ClientId); fromDb.Subject.ShouldBe(consent.Subject); }
public async Task UpdatesTheExistingConsentIfItExists(NpgsqlConsentStore store, Consent consent, IEnumerable<string> newScopes) { // Given await store.UpdateAsync(consent); // When consent.Scopes = newScopes; await store.UpdateAsync(consent); // Then var fromDb = await store.LoadAsync(consent.Subject, consent.ClientId); fromDb.ShouldNotBe(null); fromDb.ClientId.ShouldBe(consent.ClientId); fromDb.Subject.ShouldBe(consent.Subject); fromDb.Scopes.All(newScopes.Contains).ShouldBe(true); }
public Task<Consent> LoadAsync(string subject, string client) { var found = dataModel.Consents.SingleOrDefault(x => x.Subject == subject && x.ClientId == client); if (found == null) { return Task.FromResult<Consent>(null); } var result = new Consent { Subject = found.Subject, ClientId = found.ClientId, Scopes = ParseScopes(found.Scopes) }; return Task.FromResult(result); }
public async Task<Consent> LoadAsync(string subject, string client) { var found = await dataModel.Consents.SingleOrDefaultAsync(x => x.Subject == subject && x.ClientId == client); if (found == null) { return null; } var result = new Consent { Subject = found.Subject, ClientId = found.ClientId, Scopes = ParseScopes(found.Scopes) }; return result; }
public async Task<Models.Consent> LoadAsync(string subject, string client) { var found = await context.Consents .Where(x => x.SubjectId == subject && x.ClientId == client) .FirstOrDefaultAsync(); if (found == null) { return null; } var result = new Models.Consent { Subject = found.SubjectId, ClientId = found.ClientId, Scopes = found.Scopes.ParseScopes() }; return result; }
/// <summary> /// Persists the subject's consent. /// </summary> /// <param name="consent">The consent.</param> /// <returns></returns> public Task UpdateAsync(Consent consent) { // makes a snapshot as a DB would consent.Scopes = consent.Scopes.ToArray(); var query = from c in _consents where c.Subject == consent.Subject && c.ClientId == consent.ClientId select c; var item = query.SingleOrDefault(); if (item != null) { item.Scopes = consent.Scopes; } else { _consents.Add(consent); } return Task.FromResult(0); }
public async Task <Models.Consent> LoadAsync(string subject, string client) { var found = await context.Consents .Where(x => x.SubjectId == subject && x.ClientId == client) .FirstOrDefaultAsync(); if (found == null) { return(null); } var result = new Models.Consent { Subject = found.SubjectId, ClientId = found.ClientId, Scopes = found.Scopes.ParseScopes() }; return(result); }
public async Task UpdateAsync(Consent consent) { await _userStore.CreateOrUpdateConsentAsync(consent.ClientId, consent.Subject, string.Join(" ", consent.Scopes)); }
/// <summary> /// Updates the consent. /// </summary> /// <param name="client">The client.</param> /// <param name="subject">The subject.</param> /// <param name="scopes">The scopes.</param> /// <returns></returns> public virtual async Task UpdateConsentAsync(Client client, ClaimsPrincipal subject, IEnumerable<string> scopes) { if (client == null) throw new ArgumentNullException("client"); if (subject == null) throw new ArgumentNullException("subject"); if (client.AllowRememberConsent) { var subjectId = subject.GetSubjectId(); var clientId = client.ClientId; if (scopes != null && scopes.Any()) { var consent = new Consent { Subject = subjectId, ClientId = clientId, Scopes = scopes }; await _store.UpdateAsync(consent); } else { await _store.RevokeAsync(subjectId, clientId); } } }
private Task<bool> ConsentExistsInTable(Consent consent) { return _conn.ExecuteCommand(_rowExistsQuery, async cmd => { cmd.Parameters.AddWithValue("subject", consent.Subject); cmd.Parameters.AddWithValue("client", consent.ClientId); var rowCount = (long)await cmd.ExecuteScalarAsync(); return rowCount > 0; }); }
public async Task UpdateAsync(Consent consent) { var document = consent.ToDocument(); await _repository.UpsertConsent(document); }
public async Task LoadsOnlyTheConsentsGivenForTheSubject(NpgsqlConsentStore store, Consent consent1, Consent consent2) { // Given await store.UpdateAsync(consent1); await store.UpdateAsync(consent2); // When var fromDb = await store.LoadAllAsync(consent1.Subject); // Then fromDb.Count().ShouldBe(1); fromDb.Single().Subject.ShouldBe(consent1.Subject); }
/// <summary> /// Updates the consent for a subject and client. /// </summary> /// <param name="consent">The consent</param> /// <returns></returns> public async Task UpdateAsync(Consent consent) { var entity = new ConsentEntity { PartitionKey = consent.Subject, RowKey = consent.ClientId, Scopes = string.Join(",",consent.Scopes) }; var op = TableOperation.InsertOrReplace(entity); await _table.Value.ExecuteAsync(op); }
public static ConsentRow Convert(Consent consent) { Preconditions.IsNotNull(consent, nameof(consent)); return new ConsentRow { ClientId = consent.ClientId, Subject = consent.Subject, ScopesAsString = SerializeScopes(consent.Scopes) }; }
public async Task LoadsAllConsentsForASubject(NpgsqlConsentStore store, Consent consent1, Consent consent2) { // Given consent2.Subject = consent1.Subject; await store.UpdateAsync(consent1); await store.UpdateAsync(consent2); // When var fromDb = await store.LoadAllAsync(consent1.Subject); // Then fromDb.Count().ShouldBe(2); fromDb.ShouldContain(x => x.ClientId == consent1.ClientId); fromDb.ShouldContain(x => x.ClientId == consent2.ClientId); fromDb.ShouldContain(x => x.Scopes.All(y => consent1.Scopes.Contains(y))); fromDb.ShouldContain(x => x.Scopes.All(y => consent2.Scopes.Contains(y))); }
public async Task UpdateAsync(Consent consent) { Preconditions.IsNotNull(consent, nameof(consent)); var consentExistsTask = ConsentExistsInTable(consent); var row = ConsentRow.Convert(consent); if (await consentExistsTask) { // Update await _conn.ExecuteCommand(_updateQuery, async cmd => { cmd.Parameters.AddWithValue("subject", row.Subject); cmd.Parameters.AddWithValue("client", row.ClientId); cmd.Parameters.AddWithValue("scopes", row.ScopesAsString); int rowsAffected = await cmd.ExecuteNonQueryAsync(); return rowsAffected; }); } else { // Insert await _conn.ExecuteCommand(_insertQuery, async cmd => { cmd.Parameters.AddWithValue("subject", row.Subject); cmd.Parameters.AddWithValue("client", row.ClientId); cmd.Parameters.AddWithValue("scopes", row.ScopesAsString); int rowsAffected = await cmd.ExecuteNonQueryAsync(); return rowsAffected; }); } }