Пример #1
0
        public async Task<TunesUser> SignInUser(string userName, string password)
        {
            TunesUser tunesUser = null;
            if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password))
            {
                string strUrl = string.Format("{0}/token", this.ServiceUrl);

                var authClient = new OAuth2Client(
                    new Uri(strUrl),
                    "BSEtunes",
                    OAuthClientSercret);
                try
                {
                    this.TokenResponse = await authClient.RequestResourceOwnerPasswordAsync(userName, password);
                    if (this.TokenResponse != null)
                    {
						//if (this.TokenResponse..IsError)
						//{
						//	throw new UnauthorizedAccessException(this.m_strUnauthorizedAccessExceptionMessage);
						//}

                        Windows.Storage.ApplicationData.Current.RoamingSettings.Values["username"] = userName;

                        Windows.Security.Credentials.PasswordVault vault = new Windows.Security.Credentials.PasswordVault();
                        PasswordCredential passwordCredential = new PasswordCredential(PasswordVaultResourceName, userName, password);
                        vault.Add(passwordCredential);

                        if (passwordCredential != null)
                        {
                            tunesUser = this.User = new TunesUser
                            {
                                UserName = userName,
                                Password = vault.Retrieve(PasswordVaultResourceName, passwordCredential.UserName).Password
                            };
                        }
                    }
                }
                catch (Exception)
                {
                    throw new UnauthorizedAccessException(this.m_strUnauthorizedAccessExceptionMessage);
                }
            }
            else
            {
                throw new UnauthorizedAccessException(this.m_strUnauthorizedAccessExceptionMessage);
            }
            return tunesUser;
        }
Пример #2
-1
 public async Task<TunesUser> VerifyUserCredentials()
 {
     TunesUser tunesUser = null;
     Windows.Security.Credentials.PasswordVault vault = new Windows.Security.Credentials.PasswordVault();
     try
     {
         await Task.Run(() =>
         {
             var userName = (string)Windows.Storage.ApplicationData.Current.RoamingSettings.Values["username"];
             if (!string.IsNullOrEmpty(userName))
             {
                 var passwordCredential = vault.Retrieve(PasswordVaultResourceName, userName);
                 if (passwordCredential != null)
                 {
                     tunesUser = this.User = new TunesUser
                     {
                         UserName = userName,
                         Password = vault.Retrieve(PasswordVaultResourceName, passwordCredential.UserName).Password
                     };
                 }
             }
         });
     }
     catch { }
     return tunesUser;
 }