Пример #1
0
        public void Save(SlackAuthInfo info)
        {
            var slackUser = new SlackUser
            {
                AccessToken = info.AccessToken,
                TeamName    = info.TeamName,
                Filter      = new SlackNotificationFilter()
            };
            var repo = ServiceLocator.Instance.GetInstance <SlackUserRepository>();

            repo.Save(slackUser);
        }
Пример #2
0
        public Task <SlackAuthInfo> ProcessAuth(string code)
        {
            return(Task.Run(() =>
            {
                using (var client = new HttpClient())
                {
                    var url = $"https://slack.com/api/oauth.access?client_id={CLIENT_ID}&client_secret={CLIENT_SECRET}&code={code}";
                    client.Timeout = TimeSpan.FromSeconds(10);
                    var task = client.GetStringAsync(url);
                    task.Wait();
                    var json = DynamicJson.Parse(task.Result);
                    if (!json.ok)
                    {
                        throw new SlackAuthException(json.error);
                    }

                    var slackAuthInfo = new SlackAuthInfo(json.access_token, json.scope, json.user_id, json.team_name, json.team_id);
                    return slackAuthInfo;
                }
            }));
        }