Beispiel #1
0
        public async Task <IActionResult> OnGet(string code, string state)
        {
            if (code == null &&
                state == null)
            {
                return(Page());
            }
            else if (code.Equals("logout"))
            {
                await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);

                return(RedirectToPage("/"));
            }
            if (!state.Equals(Request.Host.GetHashCode().ToString(), StringComparison.CurrentCulture))
            {
                NotificationMessage = "Something went wrong while logging in";
                return(Page());
            }

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, $"https://discord.com/api/oauth2/token?client_id={SkyBotConfig.DiscordClientId}&client_secret={SkyBotConfig.DiscordClientSecret}&grant_type=authorization_code&code={code}&redirect_uri=http%3A%2F%2Fwindows.dra-gon.wtf%3A40005%2FLogin&scope=identify");

            //HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, $"https://discord.com/api/oauth2/token?client_id={SkyBotConfig.DiscordClientId}&client_secret={SkyBotConfig.DiscordClientSecret}&grant_type=authorization_code&code={code}&redirect_uri=https%3A%2F%2Flocalhost%3A44327%2FLogin&scope=identify");
            _ = request.Headers.TryAddWithoutValidation("Content-Type", "application/x-www-form-urlencoded");
            request.Content = new FormUrlEncodedContent(new Dictionary <string, string>()
            {
                { "client_id", SkyBotConfig.DiscordClientId },
                { "client_secret", SkyBotConfig.DiscordClientSecret },
                { "grant_type", "authorization_code" },
                { "code", code },
                { "redirect_uri", "http://windows.dra-gon.wtf:40005/Login" },
                //{"redirect_uri", "https://*****:*****@me");
            request.Headers.TryAddWithoutValidation("Authorization", $"Bearer {oauth.AccessToken}");

            response = await client.SendAsync(request);

            json = await response.Content.ReadAsStringAsync();

            DSharpPlus.Entities.DiscordUser user = Newtonsoft.Json.JsonConvert.DeserializeObject <DSharpPlus.Entities.DiscordUser>(json);

            if (user == null)
            {
                NotificationMessage = "Unable to get serialize user, please report this bug";
                return(Page());
            }

            return(await LoginUser((long)user.Id, user.Username));
        }
Beispiel #2
0
        public async Task <BotJogador> GetJogadorAsync(ulong id, DSharpPlus.Entities.DiscordUser user)
        {
            var jogador = await Jogadores.Find(x => x.Id == id).FirstOrDefaultAsync();

            if (jogador == null)
            {
                jogador = new WafclastJogador(id);
                jogador.Personagem.Mochila.TryAddItem(Armas.BronzeDaggerAb());
            }
            return(new BotJogador(jogador, this, user));
        }
Beispiel #3
0
 }; public static System.String BetterMention(this DSharpPlus.Entities.DiscordUser user) => $"<@{user.Id}>"; } }
Beispiel #4
0
 public UserObject(DSharpPlus.Entities.DiscordUser _user)
 {
     user = _user;
 }
 public DiscordUserDto(DSharpPlus.Entities.DiscordUser resultJson)
 {
     Email    = resultJson.Email;
     Id       = resultJson.Id;
     Username = resultJson.Username;
 }