private async void Login_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                await auth0.LoginAsync();

                //var user = await auth0.LoginAsync("google-oauth2");
                //var user = await auth0.LoginAsync("sql-azure-database", "*****@*****.**", "bar");
            }
            catch (AuthenticationCancelException)
            {
                return;
            }
            catch (AuthenticationErrorException ex)
            {
                // can't await in catch (until C# 6) avoid complicated error handling
                System.Diagnostics.Debug.WriteLine("Error:" + ex.Message);
                return;
            }

            await MessageHelpers.ShowDialogAsync(
                string.Format(
                    "Your email: {0}\r\nYour id_token: {1}",
                    auth0.CurrentUser.Profile["email"], auth0.CurrentUser.IdToken));

            var command = await MessageHelpers.ShowOKCancelAsync(
                "Do you want a delegation token to call another API?",
                "Delegation Token");

            if (command.Label == "OK")
            {
                var targetClientId = "HmqDkk9qtDgxsiSKpLKzc51xD75hgiRW";
                var options        = new Dictionary <string, string>
                {
                    { "scope", "openid profile" }
                };

                var delegationResult = await auth0.GetDelegationToken(targetClientId, options);

                await MessageHelpers.ShowDialogAsync(string.Format("Your delegation token: {0}", delegationResult["id_token"]));
            }
        }
예제 #2
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                await auth0.LoginAsync();

                //var user = await auth0.LoginAsync("google-oauth2");
                //var user = await auth0.LoginAsync("sql-azure-database", "*****@*****.**", "bar");
            }
            catch (AuthenticationCancelException)
            {
                return;
            }
            catch (AuthenticationErrorException ex)
            {
                MessageBox.Show("Error: " + ex.Message);
                return;
            }

            MessageBox.Show(
                string.Format(
                    "Your email: {0}\r\nYour id_token: {1}",
                    auth0.CurrentUser.Profile["email"], auth0.CurrentUser.IdToken));

            if (MessageBox.Show(
                    "Do you want a delegation token to call another API?",
                    "Delegation Token",
                    MessageBoxButton.OKCancel) == MessageBoxResult.OK)
            {
                var targetClientId = "HmqDkk9qtDgxsiSKpLKzc51xD75hgiRW";
                var options        = new Dictionary <string, string>
                {
                    { "scope", "openid profile" }
                };

                var delegationResult = await auth0.GetDelegationToken(targetClientId, options);

                MessageBox.Show(
                    string.Format("Your delegation token: {0}", delegationResult["id_token"]));
            }
        }