-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeviantArtTokenWrapper.cs
30 lines (24 loc) · 1.01 KB
/
DeviantArtTokenWrapper.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
using ArtworkInbox.Data;
using DeviantArtFs;
using System;
using System.Threading.Tasks;
namespace ArtworkInbox {
public class DeviantArtTokenWrapper : IDeviantArtRefreshableAccessToken {
private readonly ApplicationDbContext _context;
private readonly UserDeviantArtToken _token;
public DeviantArtApp App { get; }
public DeviantArtTokenWrapper(DeviantArtApp app, ApplicationDbContext context, UserDeviantArtToken token) {
App = app ?? throw new ArgumentNullException(nameof(app));
_context = context;
_token = token;
}
public string RefreshToken => _token.RefreshToken;
public string AccessToken => _token.AccessToken;
public async Task RefreshAccessTokenAsync() {
var resp = await DeviantArtAuth.RefreshAsync(App, _token.RefreshToken);
_token.RefreshToken = resp.refresh_token;
_token.AccessToken = resp.access_token;
await _context.SaveChangesAsync();
}
}
}