コード例 #1
0
        private async Task <WebAccount> GetWebAccount()
        {
            String accountID  = ApplicationData.Current.LocalSettings.Values[Constants.StoredAccountIdKey] as String;
            String providerID = ApplicationData.Current.LocalSettings.Values[Constants.StoredProviderIdKey] as String;

            WebAccount account = null;

            try
            {
                WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(providerID);

                account = await WebAuthenticationCoreManager.FindAccountAsync(provider, accountID);

                // The account has been deleted if FindAccountAsync returns null
                if (account == null)
                {
                    DebugPrint("cannot find the account, which might be removed from Settings.");
                    RemoveAccountData();
                }
            }
            catch (Exception ex)
            {
                DebugPrint("GetWebAccount exception: " + ex.Message);
            }

            return(account);
        }
コード例 #2
0
        private async Task <WebTokenRequestResult?> SilentAuthAsync()
        {
            // Ref: https://docs.microsoft.com/en-us/windows/uwp/security/web-account-manager#store-the-account-for-future-use

            string providerId = _userSettings.Get <string>(UserSettingsConstants.CurrentUserProviderId);
            string accountId  = _userSettings.Get <string>(UserSettingsConstants.CurrentUserId);

            if (string.IsNullOrWhiteSpace(providerId) || string.IsNullOrWhiteSpace(accountId))
            {
                return(null);
            }

            try
            {
                WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(providerId);

                WebAccount account = await WebAuthenticationCoreManager.FindAccountAsync(provider, accountId);

                WebTokenRequest       request = new WebTokenRequest(provider, Scope, _clientId);
                WebTokenRequestResult result  = await WebAuthenticationCoreManager.GetTokenSilentlyAsync(request, account);

                return(result);
            }
            catch
            {
                return(null);
            }
        }
コード例 #3
0
        private async Task AddWebAccount(AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(MicrosoftAccountProviderId, ConsumerAuthority);

            String     accountID = (String)ApplicationData.Current.LocalSettings.Values[StoredAccountKey];
            WebAccount account   = await WebAuthenticationCoreManager.FindAccountAsync(provider, accountID);

            WebAccountProvider web      = new WebAccountProvider("818", "MicrosoftAccount", new Uri("ms-appdata:///local/ProfilePicture.jpg"));
            WebAccount         account2 = new WebAccount(web, (string)ApplicationData.Current.LocalSettings.Values[StoredEmailKey], WebAccountState.Connected);

            if (account == null)
            {
                ApplicationData.Current.LocalSettings.Values.Remove(StoredAccountKey);
            }
            if (ApplicationData.Current.LocalSettings.Values.ContainsKey(StoredEmailKey))
            {
                WebAccountCommand command = new WebAccountCommand(account2, WebAccountInvoked, SupportedWebAccountActions.Remove);
                e.WebAccountCommands.Add(command);
            }
            else
            {
                WebAccountCommand command = new WebAccountCommand(account, WebAccountInvoked, SupportedWebAccountActions.Remove);
                e.WebAccountCommands.Add(command);
            }
        }
        /// <summary>
        /// Signs the current user out and clears his account information.
        /// </summary>
        public async Task SignOutAccountAsync()
        {
            if (ApplicationData.Current.LocalSettings.Values.ContainsKey(CurrentUserKey))
            {
                WebAccountProvider providertoDelete = await WebAuthenticationCoreManager.FindAccountProviderAsync(
                    MicrosoftAccountProviderId,
                    ConsumerAuthority);

                WebAccount accountToDelete = await WebAuthenticationCoreManager.FindAccountAsync(
                    providertoDelete,
                    (string)ApplicationData.Current.LocalSettings.Values[CurrentUserKey]);

                if (accountToDelete != null)
                {
                    await accountToDelete.SignOutAsync();
                }

                ApplicationData.Current.LocalSettings.Values.Remove(CurrentUserKey);
                ApplicationData.Current.LocalSettings.Values.Remove(CurrentUserProviderKey);

                UserIsSignedIn = false;
                UserSignInChange(this, false);

                Debug.WriteLine("Successfully logged out");
            }
        }
コード例 #5
0
 public async Task <WebAccount> FindAccountAsync(WebAccountProvider provider, string wamAccountId)
 {
     using (_logger.LogBlockDuration("WAM:FindAccountAsync:"))
     {
         return(await WebAuthenticationCoreManager.FindAccountAsync(provider, wamAccountId));
     }
 }
コード例 #6
0
        public static async Task <List <Tuple <string, string> > > GetMSAccounts()
        {
            WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync("https://login.microsoft.com", "consumers");

            int status = GetMSAccounts(out string[] accountNames, out string[] accountIds, out int accountCount);

            if (status >= ZL_ERRORS_START && status <= ZL_ERRORS_END)
            {
                throw new BackendException(status);
            }
            else if (status != 0)
            {
                Marshal.ThrowExceptionForHR(status);
            }
            var accounts = accountNames.Zip(accountIds, Tuple.Create).ToList();

            foreach (var account in accounts.ToList())
            {
                if (await WebAuthenticationCoreManager.FindAccountAsync(provider, account.Item2) == null)
                {
                    accounts.Remove(account);
                }
            }
            return(accounts);
        }
コード例 #7
0
        private async Task <WebAccount> GetWebAccount()
        {
            String accountID  = ApplicationData.Current.LocalSettings.Values[StoredAccountIdKey] as String;
            String providerID = ApplicationData.Current.LocalSettings.Values[StoredProviderIdKey] as String;
            String authority  = ApplicationData.Current.LocalSettings.Values[StoredAuthorityKey] as String;

            WebAccount account;

            WebAccountProvider provider = await GetProvider(providerID);

            if (providerID == AppSpecificProviderId)
            {
                account = new WebAccount(provider, accountID, WebAccountState.None);
            }
            else
            {
                account = await WebAuthenticationCoreManager.FindAccountAsync(provider, accountID);

                // The account has been deleted if FindAccountAsync returns null
                if (account == null)
                {
                    RemoveAccountData();
                }
            }

            return(account);
        }
コード例 #8
0
        private async void FindAccount_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(AccountId.Text))
            {
                DebugPrint("Error: Account Id is required");
                return;
            }

            if (currentWebAccountProvider != null)
            {
                var account = await WebAuthenticationCoreManager.FindAccountAsync(currentWebAccountProvider, AccountId.Text);

                if (account != null)
                {
                    DebugPrint($"Found. Acct: {account.Id},UserName{account.UserName}");
                }
                else
                {
                    DebugPrint("Account not found");
                }
            }
            else
            {
                DebugPrint("Error: You must first select a provider");
            }
        }
コード例 #9
0
ファイル: App.xaml.cs プロジェクト: Kavtorev/MemoMap
        //retrieving token from storage
        public async Task <string> GetTokenSilentlyAsync()
        {
            string providerId = ApplicationData.Current.LocalSettings.Values["CurrentUserProviderId"]?.ToString();
            string accountId  = ApplicationData.Current.LocalSettings.Values["CurrentUserId"]?.ToString();

            if (null == providerId || null == accountId)
            {
                return(null);
            }
            WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(providerId);

            WebAccount account = await WebAuthenticationCoreManager.FindAccountAsync(provider, accountId);

            WebTokenRequest       request = new WebTokenRequest(provider, "wl.basic");
            WebTokenRequestResult result  = await WebAuthenticationCoreManager.GetTokenSilentlyAsync(request, account);

            if (result.ResponseStatus == WebTokenRequestStatus.UserInteractionRequired)
            {
                // Unable to get a token silently - you'll need to show the UI
                return(null);
            }
            else if (result.ResponseStatus == WebTokenRequestStatus.Success)
            {
                // Success
                return(result.ResponseData[0].Token);
            }
            else
            {
                // Other error
                return(null);
            }
        }
コード例 #10
0
        public static async Task <ImageMenuItem> SignIn()
        {
            provider = await GetProvider();

            String     accountID = (String)ApplicationData.Current.LocalSettings.Values[StoredAccountKey];
            WebAccount account   = await WebAuthenticationCoreManager.FindAccountAsync(provider, accountID);

            WebTokenRequest       webTokenRequest       = new WebTokenRequest(provider, GraphScope, AccountClientId);
            WebTokenRequestResult webTokenRequestResult = await WebAuthenticationCoreManager.RequestTokenAsync(webTokenRequest, account);

            if (webTokenRequestResult.ResponseStatus == WebTokenRequestStatus.Success)
            {
                ApplicationData.Current.LocalSettings.Values.Remove(StoredAccountKey);
                ApplicationData.Current.LocalSettings.Values[StoredAccountKey] = webTokenRequestResult.ResponseData[0].WebAccount.Id;
                ImageMenuItem userDetails = await GetUser(webTokenRequestResult.ResponseData[0].Token, FullName);

                ApplicationData.Current.LocalSettings.Values[StoredNameKey] = userDetails.AccountName;
                ImageMenuItem userDetail = await GetUser(webTokenRequestResult.ResponseData[0].Token, Email);

                ApplicationData.Current.LocalSettings.Values[StoredEmailKey] = userDetail.AccountName;
                userDetails.Arguments = userDetail.AccountName;
                return(userDetails);
            }
            return(null);
        }
コード例 #11
0
        async private Task <WebAccount> TryGetUserAccount(WebAccountProvider provider)
        {
            string accountId = Windows.Storage.ApplicationData.Current.LocalSettings.Values["CurrentUserId"]?.ToString();

            if (string.IsNullOrEmpty(accountId))
            {
                return(null);
            }

            return(await WebAuthenticationCoreManager.FindAccountAsync(provider, accountId));
        }
        public async Task <WebAccount> FindAccountAsync(WebAccountProvider provider, string wamAccountId)
        {
            using (_logger.LogBlockDuration("WAM:FindAccountAsync:"))
            {
                if (_logger.IsLoggingEnabled(LogLevel.Verbose))
                {
                    _logger.VerbosePii(provider.ToLogString(true), provider.ToLogString(false));
                }

                return(await WebAuthenticationCoreManager.FindAccountAsync(provider, wamAccountId));
            }
        }
コード例 #13
0
        public async Task <WebAccount> GetAccountAsync()
        {
            var webAccountProvider = await WebAuthenticationCoreManager.FindAccountProviderAsync(_settings.WebAccountProviderId, _settings.Authority);

            var userId = _appSettings.Values["userId"];

            if (string.IsNullOrWhiteSpace(userId as string))
            {
                return(null);
            }

            return(await WebAuthenticationCoreManager.FindAccountAsync(webAccountProvider, (string)userId));
        }
コード例 #14
0
        private async Task <WebAccount> GetSignedUser()
        {
            WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(MSAProviderId, ConsumerAuthority);

            String     accountID = (String)ApplicationData.Current.LocalSettings.Values[StoredAccountKey];
            WebAccount account   = await WebAuthenticationCoreManager.FindAccountAsync(provider, accountID);

            if (account == null)
            {
                ApplicationData.Current.LocalSettings.Values.Remove(StoredAccountKey);
                ApplicationData.Current.LocalSettings.Values.Remove(StoredAccountProviderKey);
            }

            return(account);
        }
        /// <summary>
        /// Gets the currently saved user account.
        /// </summary>
        private async Task <WebAccount> GetCurrentAccountAsync()
        {
            string providerId = ApplicationData.Current.LocalSettings.Values[CurrentUserProviderKey]?.ToString();
            string accountId  = ApplicationData.Current.LocalSettings.Values[CurrentUserKey]?.ToString();

            if (providerId == null || accountId == null)
            {
                return(null);
            }

            WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(providerId);

            WebAccount account = await WebAuthenticationCoreManager.FindAccountAsync(provider, accountId);

            return(account);
        }
コード例 #16
0
        // 将指定的 web 账号添加到账号管理界面中
        private async Task ShowLogoutUI(AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(MicrosoftAccountProviderId, ConsumerAuthority);

            WebAccount account = await WebAuthenticationCoreManager.FindAccountAsync(provider, _userId);

            if (account != null)
            {
                // 最后一个参数用于指定当用户选择了账号后,会出现哪些功能按钮(我这里测试只有 SupportedWebAccountActions.Remove 是有效的)
                WebAccountCommand command = new WebAccountCommand(account, WebAccountCommandInvoked, SupportedWebAccountActions.Remove);
                e.WebAccountCommands.Add(command);
            }
            else
            {
                _userId = null;
            }
        }
コード例 #17
0
 private void CheckUserSignedOut()
 {
     try
     {
         if (this.IsSignedIn)
         {
             var signedInAccount = WebAuthenticationCoreManager.FindAccountAsync(this.provider, this.WebAccountId);
             if (signedInAccount == null)
             {
                 this.UserSignedOut();
             }
         }
     }
     catch (Exception)
     {
         this.UserSignedOut();
     }
 }
コード例 #18
0
        public static async Task <string> GetWUToken(string accountId)
        {
            WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync("https://login.microsoft.com", "consumers");

            WebAccount account = await WebAuthenticationCoreManager.FindAccountAsync(provider, accountId);

            WebTokenRequest request = new WebTokenRequest(provider, "service::dcat.update.microsoft.com::MBI_SSL", "{28520974-CE92-4F36-A219-3F255AF7E61E}");

            WebTokenRequestResult result = await WebAuthenticationCoreManager.GetTokenSilentlyAsync(request, account);

            string token       = result.ResponseData[0].Token;
            var    tokenBinary = CryptographicBuffer.ConvertStringToBinary(token, BinaryStringEncoding.Utf16LE);
            var    tokenBase64 = CryptographicBuffer.EncodeToBase64String(tokenBinary);

            Trace.WriteLine("Token = " + token);
            Trace.WriteLine("TokenBase64 = " + tokenBase64);
            return(tokenBase64);
        }
コード例 #19
0
        /// <summary>
        /// Log off and remove user from stored data
        /// </summary>
        /// <returns></returns>
        private async Task LogoffAndRemoveAccount()
        {
            if (ApplicationData.Current.LocalSettings.Values.ContainsKey(StoredAccountKey))
            {
                WebAccountProvider providertoDelete = await WebAuthenticationCoreManager.FindAccountProviderAsync(MSAProviderId, ConsumerAuthority);

                WebAccount accountToDelete = await WebAuthenticationCoreManager.FindAccountAsync(providertoDelete, (string)ApplicationData.Current.LocalSettings.Values[StoredAccountKey]);

                if (accountToDelete != null)
                {
                    await accountToDelete.SignOutAsync();
                }

                ApplicationData.Current.LocalSettings.Values.Remove(StoredAccountKey);
                ApplicationData.Current.LocalSettings.Values.Remove(StoredAccountProviderKey);
                CustomSettings.IsUserLogged = false;
            }
        }
        private async Task LogoffAndRemoveAccount()
        {
            if (ApplicationData.Current.LocalSettings.Values.ContainsKey(StoredAccountKey))
            {
                WebAccountProvider providertoDelete = await WebAuthenticationCoreManager.FindAccountProviderAsync(MicrosoftAccountProviderId, ConsumerAuthority);

                WebAccount accountToDelete = await WebAuthenticationCoreManager.FindAccountAsync(providertoDelete, (string)ApplicationData.Current.LocalSettings.Values[StoredAccountKey]);

                if (accountToDelete != null)
                {
                    await accountToDelete.SignOutAsync();
                }

                ApplicationData.Current.LocalSettings.Values.Remove(StoredAccountKey);

                SignInButton.Content = "Sign in";
            }
        }
        private async Task AddWebAccount(AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(MicrosoftAccountProviderId, ConsumerAuthority);

            String     accountID = (String)ApplicationData.Current.LocalSettings.Values[StoredAccountKey];
            WebAccount account   = await WebAuthenticationCoreManager.FindAccountAsync(provider, accountID);

            if (account == null)
            {
                // The account has most likely been deleted in Windows settings
                // Unless there would be significant data loss, you should just delete the account
                // If there would be significant data loss, prompt the user to either re-add the account, or to remove it
                ApplicationData.Current.LocalSettings.Values.Remove(StoredAccountKey);
            }

            WebAccountCommand command = new WebAccountCommand(account, WebAccountInvoked, SupportedWebAccountActions.Remove);

            e.WebAccountCommands.Add(command);
        }
コード例 #22
0
        /// <summary>
        ///
        /// </summary>
        /// <param></param>
        /// <returns></returns>
        public static async Task <bool> SignIntoAppService()
        {
            provider = await GetProvider();

            String     accountID = (String)ApplicationData.Current.LocalSettings.Values[StoredAccountKey];
            WebAccount account   = await WebAuthenticationCoreManager.FindAccountAsync(provider, accountID);

            WebTokenRequest       webTokenRequest       = new WebTokenRequest(provider, LiveScope, AccountClientId);
            WebTokenRequestResult webTokenRequestResult = await WebAuthenticationCoreManager.RequestTokenAsync(webTokenRequest, account);

            if (webTokenRequestResult.ResponseStatus == WebTokenRequestStatus.Success)
            {
                if (await AzureAppService.SignIn(webTokenRequestResult.ResponseData[0].Token))
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #23
0
        private async Task LogoffAndRemoveAccount()
        {
            if (ApplicationData.Current.LocalSettings.Values.ContainsKey(StoredAccountKey))
            {
                WebAccountProvider providertoDelete = await WebAuthenticationCoreManager.FindAccountProviderAsync(MicrosoftAccountProviderId, ConsumerAuthority);

                WebAccount accountToDelete = await WebAuthenticationCoreManager.FindAccountAsync(providertoDelete, (string)ApplicationData.Current.LocalSettings.Values[StoredAccountKey]);

                if (accountToDelete != null)
                {
                    await accountToDelete.SignOutAsync();
                }

                ApplicationData.Current.LocalSettings.Values.Remove(StoredAccountKey);
                ApplicationData.Current.LocalSettings.Values.Remove(StoredEmailKey);
                AccountListViewItem.Visibility = Visibility.Collapsed;
                SignInListViewItem.Visibility  = Visibility.Visible;

                await Shared.Helpers.LocalStore.PurgeLocalStoreAsync();

                App.HomesViewModel = new HomesViewModel();
                App.RoomsViewModel = new RoomsViewModel();

                Frame rootFrame = Window.Current.Content as Frame;

                if (rootFrame == null)
                {
                    rootFrame = new Frame();

                    Window.Current.Content = rootFrame;
                }

                if (rootFrame.Content == null)
                {
                    bool autoSignIn = false;
                    AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested -= OnAccountCommandsRequested;
                    rootFrame.Navigate(typeof(Views.SignIn.MainPage), autoSignIn);
                }

                Window.Current.Activate();
            }
        }
コード例 #24
0
        private async Task <string> GetMsaTokenSilentlyAsync()
        {
            // Recall the provider Id and account Id from the app's storage
            string providerId = ApplicationData.Current.RoamingSettings.Values["CurrentUserProviderId"]?.ToString();
            string accountId  = ApplicationData.Current.RoamingSettings.Values["CurrentUserId"]?.ToString();

            if (null == providerId || null == accountId)
            {
                return(null);
            }

            WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(providerId);

            WebAccount account = await WebAuthenticationCoreManager.FindAccountAsync(provider, accountId);

            if (account == null)
            {
                return(null);
            }

            var request = new WebTokenRequest(provider, "wl.basic");

            // We already have the web account, so we can call GetTokenSilentlyAsync instead of RequestTokenAsync.
            WebTokenRequestResult result = await WebAuthenticationCoreManager.GetTokenSilentlyAsync(request, account);

            // Unable to get a token silently - you'll need to show the UI
            if (result.ResponseStatus == WebTokenRequestStatus.UserInteractionRequired)
            {
                return(null);
            }
            // Success
            else if (result.ResponseStatus == WebTokenRequestStatus.Success)
            {
                return(result.ResponseData[0].Token);
            }
            // Other error
            else
            {
                return(null);
            }
        }
コード例 #25
0
        public async Task <string> AcquireTokenSilentAsync()
        {
            var webAccountProvider = await WebAuthenticationCoreManager.FindAccountProviderAsync(_settings.WebAccountProviderId, _settings.Authority);

            var userId      = _appSettings.Values["userId"];
            var userAccount = await WebAuthenticationCoreManager.FindAccountAsync(webAccountProvider, (string)userId);

            var webTokenRequest = new WebTokenRequest(webAccountProvider, string.Empty, _settings.ClientId);

            webTokenRequest.Properties.Add("resource", _settings.ApiResource);
            var webTokenRequestResult = await WebAuthenticationCoreManager.GetTokenSilentlyAsync(webTokenRequest, userAccount);

            if (webTokenRequestResult.ResponseStatus == WebTokenRequestStatus.Success)
            {
                _appSettings.Values["userId"]     = userAccount.Id;
                _appSettings.Values["login_hint"] = userAccount.UserName;
                return(webTokenRequestResult.ResponseData[0].Token);
            }

            return(null);
        }
コード例 #26
0
        private async void SignOutButton_Click(object sender, RoutedEventArgs e)
        {
            var msaProvider = await WebAuthenticationCoreManager.FindAccountProviderAsync(
                "https://login.microsoft.com", "consumers");

            var request = new WebTokenRequest(msaProvider, "consumers");
            var result  = await WebAuthenticationCoreManager.GetTokenSilentlyAsync(request);

            if (result.ResponseStatus == WebTokenRequestStatus.UserInteractionRequired)
            {
                // Unable to get a token silently - you'll need to show the UI
            }
            else if (result.ResponseStatus == WebTokenRequestStatus.Success)
            {
                // Success, use your token
            }

            string id = ""; // ID obtained from calling https://apis.live.net/v5.0/me?access_token=" + token

            var webAccount = await WebAuthenticationCoreManager.FindAccountAsync(msaProvider, id);
        }
コード例 #27
0
        private async Task <WebAccount> GetWebAccount()
        {
            if (webAccount != null)
            {
                return(webAccount);
            }

            string providerId = ApplicationData.Current.LocalSettings.Values["CurrentUserProviderId"]?.ToString();
            string accountId  = ApplicationData.Current.LocalSettings.Values["CurrentUserId"]?.ToString();

            if (null == providerId || null == accountId)
            {
                return(null);
            }

            var provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(providerId);

            webAccount = await WebAuthenticationCoreManager.FindAccountAsync(provider, accountId);

            return(webAccount);
        }
コード例 #28
0
        public async Task <string> GetTokenSilentAsync(string resource = null)
        {
            if (resource == null)
            {
                resource = _resource;
            }

            var userID = GetSavedAccountId();

            if (userID != null)
            {
                var provider = await GetProvider();

                var userAccount = await WebAuthenticationCoreManager.FindAccountAsync(provider, (string)userID);

                if (userAccount != null)
                {
                    try
                    {
                        WebTokenRequest wtr = new WebTokenRequest(provider, _scope, _clientId);
                        if (resource != null)
                        {
                            wtr.Properties.Add("resource", resource);
                        }

                        var wtrr = await WebAuthenticationCoreManager.GetTokenSilentlyAsync(wtr, userAccount);

                        SaveToken(wtrr, resource);

                        return(GetTokenFromResult(wtrr));
                    }
                    catch (Exception ex)
                    {
                        ServiceUtil.LogService.Write("SignInSilent: " + ex.Message, LoggingLevel.Error);
                    }
                }
            }

            return(null);
        }
コード例 #29
0
ファイル: MSAAuth.cs プロジェクト: freistli/CentennialTest
        private async Task <List <WebAccount> > GetAllAccounts()
        {
            List <WebAccount> accounts = new List <WebAccount>();

            ApplicationDataContainer AccountListContainer = ApplicationData.Current.LocalSettings.Containers[AccountsContainer];

            foreach (Object value in AccountListContainer.Containers[ProviderIdSubContainer].Values.Keys)
            {
                String accountID  = value as String;
                String providerID = AccountListContainer.Containers[ProviderIdSubContainer].Values[accountID] as String;
                String authority  = AccountListContainer.Containers[AuthoritySubContainer].Values[accountID] as String;

                WebAccountProvider provider = await GetProvider(providerID, authority);

                if (providerID == AppSpecificProviderId)
                {
                    accounts.Add(new WebAccount(provider, accountID, WebAccountState.None));
                }
                else
                {
                    WebAccount loadedAccount = await WebAuthenticationCoreManager.FindAccountAsync(provider, accountID);

                    if (loadedAccount != null)
                    {
                        accounts.Add(loadedAccount);
                    }
                    else
                    {
                        // The account has been deleted
                        ApplicationDataContainer accountsContainer = ApplicationData.Current.LocalSettings.Containers[AccountsContainer];

                        accountsContainer.Containers[ProviderIdSubContainer].Values.Remove(accountID);
                        accountsContainer.Containers[AuthoritySubContainer].Values.Remove(accountID);
                    }
                }
            }

            return(accounts);
        }
コード例 #30
0
        private async void button1clickAsync(object sender, RoutedEventArgs e)
        {
            string providerId = ApplicationData.Current.LocalSettings.Values["CurrentUserProviderId"]?.ToString();
            string accountId  = ApplicationData.Current.LocalSettings.Values["CurrentUserId"]?.ToString();

            if ((providerId != null) & (accountId != null))
            {
                WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(providerId);

                WebAccount account = await WebAuthenticationCoreManager.FindAccountAsync(provider, accountId);

                WebTokenRequest       request = new WebTokenRequest(provider, "wl.basic");
                WebTokenRequestResult result  = await WebAuthenticationCoreManager.GetTokenSilentlyAsync(request, account);

                ApplicationData.Current.LocalSettings.Values.Remove("CurrentUserProviderId");
                ApplicationData.Current.LocalSettings.Values.Remove("CurrentUserId");
                await account.SignOutAsync();

                var messageDialog = new MessageDialog("Logged out.");
                await messageDialog.ShowAsync();
            }
        }