コード例 #1
0
        public static void SignOut()
        {
            var vault = new Windows.Security.Credentials.PasswordVault();

            vault.Remove(new Windows.Security.Credentials.PasswordCredential(
                             resourceName, DiscordUser.DiscordId, DiscordToken));

            IsLoggedIn          = false;
            DiscordToken        = "";
            DiscordRefreshToken = "";
            DiscordUser         = null;

            OnLoginStateChanged(IsLoggedIn);
        }
コード例 #2
0
        public static async Task <bool> SignIn(string discordToken, string refreshToken)
        {
            try
            {
                DiscordToken        = discordToken;
                DiscordRefreshToken = refreshToken;
                DiscordUser         = await DiscordApi.GetCurrentUser();

                var vault = new Windows.Security.Credentials.PasswordVault();
                vault.Add(new Windows.Security.Credentials.PasswordCredential(
                              resourceName, DiscordUser.DiscordId, DiscordToken));

                try
                {
                    _ = await GetCurrentUser();
                }
                catch (ApiException ex)
                {
                    var error = await ex.GetContentAsAsync <UWPCommLib.Api.UWPComm.Models.Error>();

                    if (ex.StatusCode == System.Net.HttpStatusCode.NotFound)
                    {
                        // The user does not exist yet, so create an account for them
                        await UwpCommApi.PostUser(new Dictionary <string, string>() {
                            { "name", DiscordUser.Username },
                        });
                    }
                }

                IsLoggedIn = true;
                OnLoginStateChanged(IsLoggedIn);
            }
            catch
            {
                IsLoggedIn = false;
            }
            return(IsLoggedIn);
        }