Пример #1
0
        public async Task <IActionResult> Authorize(string code, string state)
        {
            _logger.LogInformation("Authorizing!");
            var response = await _oAuthAccessClient.OAuthAccess(new OauthAccessRequest
            {
                ClientId      = _options.Value.CLIENT_ID,
                ClientSecret  = _options.Value.CLIENT_SECRET,
                Code          = code,
                SingleChannel = true
            });

            if (response.Ok)
            {
                _logger.LogInformation($"Oauth response! {response.Ok}");

                await _slackTeamRepository.Insert(new SlackTeam
                {
                    TeamId             = response.Team_Id,
                    TeamName           = response.Team_Name,
                    Scope              = response.Scope,
                    AccessToken        = response.Access_Token,
                    FplBotSlackChannel = state
                });

                return(Ok());
            }
            _logger.LogInformation($"Oauth response not ok! {response.Error}");
            return(BadRequest(response.Error));
        }
Пример #2
0
        public async Task <IActionResult> Authorize(string code, string state)
        {
            _logger.LogInformation("Authorizing!");
            var original     = new Uri(HttpContext.Request.GetDisplayUrl());
            var redirect_uri = new Uri(original, "/oauth/authorize");
            var response     = await _oAuthAccessClient.OAuthAccessV2(new OauthAccessRequestV2
            {
                ClientId     = _options.Value.CLIENT_ID,
                ClientSecret = _options.Value.CLIENT_SECRET,
                Code         = code,
                RedirectUri  = redirect_uri.ToString()
            });

            _logger.LogInformation($"OauthResponse : {JsonConvert.SerializeObject(response)}");

            if (response.Ok)
            {
                _logger.LogInformation($"Oauth response! {response.Ok}");
                var setup = ParseState(state);
                await _slackTeamRepository.Insert(new SlackTeam
                {
                    TeamId             = response.Team.Id,
                    TeamName           = response.Team.Name,
                    Scope              = response.Scope,
                    AccessToken        = response.Access_Token,
                    FplBotSlackChannel = setup.Channel,
                    FplbotLeagueId     = setup.LeagueId,
                    Subscriptions      = new List <EventSubscription> {
                        EventSubscription.All
                    }
                });

                await _messageSession.Publish(new AppInstalled(response.Team.Id, response.Team.Name, setup.LeagueId, setup.Channel));

                if (_env.IsProduction())
                {
                    return(Redirect("https://www.fplbot.app/success"));
                }
                return(Redirect("https://test.fplbot.app/success"));
            }
            _logger.LogInformation($"Oauth response not ok! {response.Error}");
            return(BadRequest(response.Error));
        }