コード例 #1
0
    /// <inheritdoc/>
    public virtual async Task StoreAsync(Duende.IdentityServer.Models.PersistedGrant token)
    {
        using var activity = Tracing.StoreActivitySource.StartActivity("PersistedGrantStore.Store");

        var existing = (await Context.PersistedGrants.Where(x => x.Key == token.Key)
                        .ToArrayAsync(CancellationTokenProvider.CancellationToken))
                       .SingleOrDefault(x => x.Key == token.Key);

        if (existing == null)
        {
            Logger.LogDebug("{persistedGrantKey} not found in database", token.Key);

            var persistedGrant = token.ToEntity();
            Context.PersistedGrants.Add(persistedGrant);
        }
        else
        {
            Logger.LogDebug("{persistedGrantKey} found in database", token.Key);

            token.UpdateEntity(existing);
        }

        try
        {
            await Context.SaveChangesAsync(CancellationTokenProvider.CancellationToken);
        }
        catch (DbUpdateConcurrencyException ex)
        {
            Logger.LogWarning("exception updating {persistedGrantKey} persisted grant in database: {error}", token.Key, ex.Message);
        }
    }
コード例 #2
0
    public void CanMap()
    {
        var model = new Duende.IdentityServer.Models.PersistedGrant()
        {
            ConsumedTime = new System.DateTime(2020, 02, 03, 4, 5, 6)
        };

        var mappedEntity = model.ToEntity();

        mappedEntity.ConsumedTime.Value.Should().Be(new System.DateTime(2020, 02, 03, 4, 5, 6));

        var mappedModel = mappedEntity.ToModel();

        mappedModel.ConsumedTime.Value.Should().Be(new System.DateTime(2020, 02, 03, 4, 5, 6));

        Assert.NotNull(mappedModel);
        Assert.NotNull(mappedEntity);
    }