Example #1
0
        private async Task <WebAccount> AddWebAccount(
            string userName, string accountId, IDictionary <string, string> properties,
            bool perUserScope, bool perAppScope, string perUserPerAppId)
        {
            if (string.IsNullOrEmpty(accountId))
            {
                //TODO:
                accountId = userName;
            }


            ReadOnlyDictionary <string, string> ro = new ReadOnlyDictionary <string, string>(properties);


            WebAccount newAccount = null;


            if (perUserScope)
            // if (perUserScope && !perAppScope )
            {
                newAccount = await WebAccountManager.AddWebAccountAsync(accountId, userName, ro, WebAccountScope.PerUser);
            }


            if (perAppScope && perUserScope)
            {
                newAccount = await WebAccountManager.AddWebAccountAsync("perapp" + accountId, userName, ro, WebAccountScope.PerApplication,
                                                                        newAccount.Id);
            }
            else if (perAppScope)
            {
                newAccount = await WebAccountManager.AddWebAccountAsync(accountId, userName, ro, WebAccountScope.PerApplication,
                                                                        perUserPerAppId);
            }


            string localPerUserPerAppid = null;

            if (perUserScope && perAppScope /* && !string.IsNullOrEmpty(perUserPerAppId)*/)
            {
                WebAccount perUserPerAppAccount = await WebAccountManager.GetPerUserFromPerAppAccountAsync(newAccount);

                if (perUserPerAppAccount != null)
                {
                    localPerUserPerAppid = perUserPerAppAccount.Id;
                    newAccount           = perUserPerAppAccount;
                }
            }

            AccountManager.Current.AddAccount(new Account()
            {
                Id = accountId, UserName = userName, PerUserPerAppId = localPerUserPerAppid
            });


            return(newAccount);
        }
Example #2
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            _operation = e.Parameter as WebAccountProviderRequestTokenOperation;

            if (_operation == null)
            {
                submitButton.IsEnabled = false;
                errorMessage.Text      = Constants.FormatError(Constants.UnexpectedOperation, Constants.NoToken);
            }
            else
            {
                if (_operation.ProviderRequest.WebAccounts.Count > 0)
                {
                    _requestedAccount = _operation.ProviderRequest.WebAccounts[0];
                    userName.Text     = _requestedAccount.UserName;

                    WebAccount account = null;
                    account = await WebAccountManager.GetPerUserFromPerAppAccountAsync(_requestedAccount);

                    Debug.Assert(account != null);
                    // TODO: You could return error if the account is not found.
                    // For the sample we let them add the account again.
                }

                // This is a hack for demo purposes to show simplest UI
                if (_operation.ProviderRequest.ClientRequest.Properties.Keys.Contains("UI"))
                {
                    string ui = _operation.ProviderRequest.ClientRequest.Properties["UI"];
                    if (ui == "Simplest")
                    {
                        for (int x = 8; x < 20; x++)
                        {
                            RootGrid.RowDefinitions[x].Height = new GridLength(0);
                        }
                    }
                }
            }
        }