forked from manuelmayer-dev/Macro-Deck-Twitch-Plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCredentialsHelper.cs
49 lines (40 loc) · 1.51 KB
/
CredentialsHelper.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
42
43
44
45
46
47
48
49
using SuchByte.MacroDeck.Logging;
using SuchByte.MacroDeck.Plugins;
using SuchByte.TwitchPlugin.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SuchByte.TwitchPlugin
{
internal static class CredentialsHelper
{
public static void UpdateCredentials(TwitchAccount twitchAccount)
{
Dictionary<string, string> credentials = new Dictionary<string, string>
{
["token"] = twitchAccount.TwitchAccessToken
};
PluginCredentials.SetCredentials(PluginInstance.Main, credentials);
}
public static TwitchAccount GetTwitchAccount()
{
TwitchAccount account = null;
try
{
List<Dictionary<string, string>> credentialsList = PluginCredentials.GetPluginCredentials(PluginInstance.Main);
if (credentialsList == null || credentialsList.Count == 0) return null;
Dictionary<string, string> credentials = credentialsList.FirstOrDefault();
if (credentials == null) return null;
account = new TwitchAccount()
{
TwitchAccessToken = credentials["token"],
};
} catch (Exception ex)
{
MacroDeckLogger.Error(PluginInstance.Main, $"Error while getting credentials: { ex.Message + Environment.NewLine + ex.StackTrace }");
}
return account;
}
}
}