public async Task <IActionResult> Get(string code, string state) { try { var serialisedState = _cypher.Decrypt(state); var stateModel = System.Text.Json.JsonSerializer.Deserialize <StateModel>(serialisedState); var accessModel = await _service.GetAccessTokenAsync(code, state); await _ownerGitHubCredentialRepository.SaveAsync(new Bot.Core.GitHubCredentials { UserId = stateModel.UserId.ToString(), TokenType = accessModel.TokenType, AccessToken = accessModel.AccessToken }); foreach (var client in _botDiscordSocketClients) { if (client.Guilds.Any(x => x.Id == stateModel.GuildId)) { var channel = (ITextChannel)client.GetChannel(stateModel.ChannelId); await channel.SendMessageAsync("Thanks, you are now authed"); } } return(Redirect($"https://discordapp.com/channels/{stateModel.GuildId}/{stateModel.ChannelId}")); } catch (Exception ex) { _logger.LogError(ex, "Poopageddon"); return(BadRequest()); } }