-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathClientStore.cs
More file actions
70 lines (63 loc) · 2.37 KB
/
ClientStore.cs
File metadata and controls
70 lines (63 loc) · 2.37 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
using IdentityServer4.NCache.Entities;
using IdentityServer4.NCache.Mappers;
using IdentityServer4.NCache.Stores.Interfaces;
using IdentityServer4.Stores;
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;
namespace IdentityServer4.NCache.Stores
{
public class ClientStore : IClientStore
{
private readonly IConfigurationStoreRepository<Client> _repository;
private readonly ILogger<ClientStore> _logger;
private readonly bool _isDebugLoggingEnabled;
private readonly bool _isErrorLoggingEnabled;
public ClientStore(
IConfigurationStoreRepository<Client> repository,
ILogger<ClientStore> logger)
{
_repository = repository ?? throw new ArgumentNullException(nameof(repository), "Repository parameter can't be null");
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_isErrorLoggingEnabled = logger.IsEnabled(LogLevel.Error);
_isDebugLoggingEnabled = logger.IsEnabled(LogLevel.Debug);
}
public async Task<Models.Client> FindClientByIdAsync(string clientId)
{
try
{
if (string.IsNullOrWhiteSpace(clientId))
{
throw new ArgumentNullException(
"client Id can't be null or white space");
}
var ncacheClient =
await _repository.GetSingleAsync($"{clientId}");
if (ncacheClient == null)
{
if (_isErrorLoggingEnabled)
{
_logger.LogError($"Client with ID {clientId} not found");
}
return null;
}
if (_isDebugLoggingEnabled)
{
_logger.LogDebug($"Client with ID {clientId} found");
}
return ncacheClient.ToModel();
}
catch (Exception ex)
{
if (_isErrorLoggingEnabled)
{
_logger.LogError(
ex,
$"Something went wrong with FindClientByIdAsync " +
$"for client id {clientId}");
}
throw;
}
}
}
}