-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathPersistedGrantStore.cs
More file actions
93 lines (77 loc) · 3.32 KB
/
PersistedGrantStore.cs
File metadata and controls
93 lines (77 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using IdentityServer4.Extensions;
using IdentityServer4.Models;
using IdentityServer4.Stores;
using Microsoft.Extensions.Logging;
using OpenActive.FakeDatabase.NET;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace IdentityServer
{
public class AcmePersistedGrantStore : IPersistedGrantStore
{
protected readonly ILogger _logger;
public AcmePersistedGrantStore(ILogger<AcmePersistedGrantStore> logger)
{
_logger = logger;
}
public async Task<IEnumerable<PersistedGrant>> GetAllAsync(PersistedGrantFilter filter)
{
filter.Validate();
var grants = await FakeBookingSystem.FakeDatabase.GetAllGrants(filter.SubjectId, filter.SessionId, filter.ClientId, filter.Type);
_logger.LogDebug("{persistedGrantCount} persisted grants found for {@filter}", grants.Count, filter);
var persistedGrants = grants.Select(grant => new PersistedGrant
{
Key = grant.Key,
Type = grant.Type,
SubjectId = grant.SubjectId,
SessionId = grant.SessionId,
ClientId = grant.ClientId,
CreationTime = grant.CreationTime,
ConsumedTime = grant.ConsumedTime,
Expiration = grant.Expiration,
Data = grant.Data
}).ToList();
return persistedGrants;
}
public async Task<PersistedGrant> GetAsync(string key)
{
var grant = await FakeBookingSystem.FakeDatabase.GetGrant(key);
_logger.LogDebug("{persistedGrantKey} found in database: {persistedGrantKeyFound}", key, grant != null);
return grant != null ? new PersistedGrant
{
Key = grant.Key,
Type = grant.Type,
SubjectId = grant.SubjectId,
SessionId = grant.SessionId,
ClientId = grant.ClientId,
CreationTime = grant.CreationTime,
ConsumedTime = grant.ConsumedTime,
Expiration = grant.Expiration,
Data = grant.Data
} : null;
}
public async Task RemoveAllAsync(PersistedGrantFilter filter)
{
filter.Validate();
_logger.LogDebug("removing all persisted grants from database for {@filter}", filter);
await FakeBookingSystem.FakeDatabase.RemoveAllGrants(filter.SubjectId, filter.SessionId, filter.ClientId, filter.Type);
}
public async Task RemoveAsync(string key)
{
_logger.LogDebug("removing {persistedGrantKey} persisted grant from database", key);
await FakeBookingSystem.FakeDatabase.RemoveGrant(key);
}
public async Task StoreAsync(PersistedGrant grant)
{
if (await FakeBookingSystem.FakeDatabase.AddGrant(grant.Key, grant.Type, grant.SubjectId, grant.SessionId, grant.ClientId, grant.CreationTime, grant.ConsumedTime, grant.Expiration, grant.Data))
{
_logger.LogDebug("{persistedGrantKey} not found in database, and so was inserted", grant.Key);
}
else
{
_logger.LogDebug("{persistedGrantKey} found in database, and updated", grant.Key);
}
}
}
}