/// <summary> /// Stores the asynchronous. /// </summary> /// <param name="token">The token.</param> /// <returns></returns> public Task StoreAsync(IdentityServer4.Models.PersistedGrant token) { var existing = _persistedGrants.SingleOrDefault(x => x.Key == token.Key); if (existing == null) { _logger.LogDebug("{persistedGrantKey} not found in database", token.Key); var persistedGrant = token.ToEntity(); _persistedGrants.Add(persistedGrant); } else { _logger.LogDebug("{persistedGrantKey} found in database", token.Key); token.UpdateEntity(existing); } try { _uow.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { _logger.LogWarning("exception updating {persistedGrantKey} persisted grant in database: {error}", token.Key, ex.Message); } return(Task.FromResult(0)); }
public async Task StoreAsync(PersistedGrant token) { var persistedGrant = token.ToEntity(); Logger.LogDebug("storing persisted grant: {persistedGrant}", persistedGrant); var table = await InitTableAsync(); var operation = TableOperation.InsertOrReplace(persistedGrant); var result = await table.ExecuteAsync(operation); Logger.LogDebug("stored {persistedGrantKey} with result {result}", token.Key, result.HttpStatusCode); }
public void PersistedGrantModelToEntityConfigurationIsValid() { var model = new IdentityServer4.Models.PersistedGrant(); // TODO: set references var mappedEntity = model.ToEntity(); var mappedModel = mappedEntity.ToModel(); Assert.NotNull(mappedModel); Assert.NotNull(mappedEntity); PersistedGrantMappers.Mapper.ConfigurationProvider.AssertConfigurationIsValid(); }
public async Task StoreAsync(IdentityServer4.Models.PersistedGrant grant) { var existingGrant = _identityDbContext.PersistedGrants.SingleOrDefault(pg => pg.Key == grant.Key); if (existingGrant == null) { var persistedGrantEntity = grant.ToEntity(); _identityDbContext.PersistedGrants.Add(persistedGrantEntity); } else { grant.ToEntity(existingGrant); } try { await _identityDbContext.SaveChangesAsync(); } catch (DbUpdateConcurrencyException ex) { _logger.Warning("Exception updating {grantKey}. Error: {error}", grant.Key, ex.Message); } }
public async Task StoreAsync(IdentityServer4.Models.PersistedGrant grant) { var existingGrant = IdentityDbContext.PersistedGrants.SingleOrDefault(pg => pg.Key == grant.Key); Event evt; if (existingGrant == null) { var persistedGrantEntity = grant.ToEntity(); IdentityDbContext.PersistedGrants.Add(persistedGrantEntity); evt = new EntityCreatedAuditEvent <PersistedGrant>( UserResolverService.Username, UserResolverService.ClientId, UserResolverService.Subject, persistedGrantEntity.Key, persistedGrantEntity, SerializationSettings); } else { grant.ToEntity(existingGrant); evt = new EntityUpdatedAuditEvent <PersistedGrant>( UserResolverService.Username, UserResolverService.ClientId, UserResolverService.Subject, existingGrant.Key, existingGrant, SerializationSettings); } try { await IdentityDbContext.SaveChangesAsync(); await EventService.RaiseAsync(evt); } catch (DbUpdateConcurrencyException ex) { _logger.Warning("Exception updating {grantKey}. Error: {error}", grant.Key, ex.Message); } }