-
Notifications
You must be signed in to change notification settings - Fork 2
/
MemoryTokenStore.cs
41 lines (32 loc) · 1.04 KB
/
MemoryTokenStore.cs
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
using System.Collections.Generic;
using System.Threading.Tasks;
using Xero.NetStandard.OAuth2.Client;
using Xero.NetStandard.OAuth2.Token;
namespace XeroPracticeManagerOAuth2Sample.Example
{
public class MemoryTokenStore
{
private readonly Dictionary<string, IXeroToken> _tokens;
private readonly IXeroClient _xeroClient;
public MemoryTokenStore(IXeroClient xeroClient)
{
_xeroClient = xeroClient;
_tokens = new Dictionary<string, IXeroToken>();
}
public async Task<IXeroToken> GetAccessTokenAsync(string xeroUserId)
{
if (!_tokens.ContainsKey(xeroUserId))
{
return null;
}
var token = _tokens[xeroUserId];
token = await _xeroClient.GetCurrentValidTokenAsync(token);
SetToken(xeroUserId, token);
return token;
}
public void SetToken(string xeroUserId, IXeroToken xeroToken)
{
_tokens[xeroUserId] = xeroToken;
}
}
}