Пример #1
0
        protected async void OnInitializedAsync(object sender, EventArgs e)
        {
            Globals.AadInstance          = GetConfigValue("b2c:AADInstance");
            Globals.RedirectUri          = GetConfigValue("b2c:RedirectUri");
            Globals.Tenant               = GetConfigValue("b2c:Tenant");
            Globals.ClientId             = GetConfigValue("b2c:ClientId");
            Globals.SignInPolicy         = GetConfigValue("b2c:SignInPolicy");
            Globals.SignUpPolicy         = GetConfigValue("b2c:SignUpPolicy");
            Globals.SignUpOrSignInPolicy = GetConfigValue("b2c:SignUpOrSignInPolicy");
            Globals.EditProfilePolicy    = GetConfigValue("b2c:ProfilePolicy");
            b2cUser = new B2CUser();

            int result = await b2cUser.InitializeAsync();

            if (b2cUser.IsSignedIn())
            {
                SignInButton.Content = "Clear Cache";
                UserName.Text        = b2cUser.Username;
                UserId.Text          = b2cUser.UserId;
                GetTodoList(true);
            }
            else
            {
                UserName.Text = "Sign In to get ToDo items";
                UserId.Text   = String.Empty;
            }
        }
Пример #2
0
        private async void SignIn(object sender = null, RoutedEventArgs args = null)
        {
            try
            {
                if (SignInButton.Content.ToString() == "Clear Cache")
                {
                    // await is not really doing much here but we want to call the webservice later to
                    // perform the signout and that will be async - for future expansion :-)
                    var blah = await b2cUser.SignOut();

                    UserName.Text        = "Sign In to get ToDo items";
                    UserId.Text          = String.Empty;
                    TodoList.ItemsSource = null;
                    SignInButton.Content = "Sign In";
                }
                else
                {
                    var blah = await b2cUser.SignUpOrIn();

                    if (b2cUser.IsSignedIn() == true)
                    {
                        SignInButton.Content = "Clear Cache";
                        UserName.Text        = b2cUser.Username;
                        UserId.Text          = b2cUser.UserId;
                        GetTodoList();
                    }
                }
            }
            catch (Exception ex)
            {
                // An unexpected error occurred.
                string message = ex.Message;
                if (ex.InnerException != null)
                {
                    message += "Inner Exception : " + ex.InnerException.Message;
                }

                MessageBox.Show(message);
            }
        }