-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOpenAuthenticator.cs
38 lines (30 loc) · 1.12 KB
/
OpenAuthenticator.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
using System.IO;
namespace ExistSpoon
{
public class OpenAuthenticator
{
private readonly OauthHost _oauthHost;
public bool FlushingProgress => _oauthHost.FlushingProgress;
public OpenAuthenticator(string clientId, string clientSecret, string redirectUri)
{
_oauthHost = new OauthHost(clientId, clientSecret, redirectUri);
}
private static string OauthTokenPath => Path.Combine(Path.GetTempPath(), "existio_oauthtoken.txt");
public string Authenticate()
{
string oauthToken;
if (File.Exists(OauthTokenPath))
{
ProgressAggregator.Publish($"Using existing oauth token from {OauthTokenPath}.");
oauthToken = File.ReadAllText(OauthTokenPath);
}
else
{
ProgressAggregator.Publish("Initiating OAuth flow.");
oauthToken = _oauthHost.Authenticate().Result;
File.WriteAllText(OauthTokenPath, oauthToken);
}
return oauthToken;
}
}
}