Example #1
0
        private static async Task AcquireTokenAsync()
        {
            TokenBroker app   = new TokenBroker();
            string      token = await GetTokenIntegratedAuthAsync(app.Sts).ConfigureAwait(false);

            Console.WriteLine(token);
        }
Example #2
0
        public SecondPage()
        {
            this.tokenBroker = new TokenBroker();

            var browseButton = new Button
            {
                Text = "Acquire Token"
            };

            var clearButton = new Button
            {
                Text = "Clear Cache"
            };

            result = new Label {
            };

            browseButton.Clicked += browseButton_Clicked;
            clearButton.Clicked  += clearButton_Clicked;

            Content = new StackLayout
            {
                VerticalOptions = LayoutOptions.Center,
                Children        =
                {
                    browseButton,
                    clearButton,
                    result
                }
            };
        }
Example #3
0
        private async void acquireTokenSilentButton_Click(object sender, EventArgs e)
        {
            this.accessTokenTextView.Text = string.Empty;
            TokenBroker tokenBroker = new TokenBroker();

            tokenBroker.Sts = sts;
            EditText email = FindViewById <EditText>(Resource.Id.email);

            tokenBroker.Sts.ValidUserName = email.Text;
            string value = null;

            try
            {
                value = await tokenBroker.GetTokenSilentAsync(new PlatformParameters(this)).ConfigureAwait(false);
            }
            catch (Java.Lang.Exception ex)
            {
                throw new Exception(ex.Message + "\n" + ex.StackTrace);
            }
            catch (Exception exc)
            {
                value = exc.Message;
            }

            this.accessTokenTextView.Text = value;
        }
        private async void conditionalAccessButton_Click(object sender, EventArgs e)
        {
            this.accessTokenTextView.Text = string.Empty;
            TokenBroker tokenBroker = new TokenBroker();

            tokenBroker.Sts = sts;
            EditText email = FindViewById <EditText>(Resource.Id.email);

            tokenBroker.Sts.ValidUserName = email.Text;
            string value = null;

            try
            {
                string policy = "{\"access_token\":{\"polids\":{\"essential\":true,\"values\":[\"5ce770ea-8690-4747-aa73-c5b3cd509cd4\"]}}}";
                value = await tokenBroker.GetTokenInteractiveAsync(new PlatformParameters(this, true), null, policy);
            }
            catch (Java.Lang.Exception ex)
            {
                throw new Exception(ex.Message + "\n" + ex.StackTrace);
            }
            catch (Exception exc)
            {
                value = exc.Message;
            }

            this.accessTokenTextView.Text = value;
        }
        static TokenBroker CreateBrokerWithSts()
        {
            var tokenBroker = new TokenBroker();

            sts.Authority     = AUTHORITY;
            sts.ValidClientId = CLIENTID;
            sts.ValidResource = RESOURCE;
            sts.ValidUserName = USER;
            sts.ValidNonExistingRedirectUri = new Uri(REDIRECT_URI);
            tokenBroker.Sts = sts;
            return(tokenBroker);
        }
Example #6
0
        public SecondPage()
        {
            this.tokenBroker = new TokenBroker();

            var acquireTokenButton = new Button
            {
                Text = "Acquire Token"
            };

            var acquireTokenSilentButton = new Button
            {
                Text = "Acquire Token Silent"
            };

            var conditionalAccessButton = new Button
            {
                Text = "Conditional Access"
            };

            var clearButton = new Button
            {
                Text = "Clear Cache"
            };

            result   = new Label {
            };
            logLabel = new Label
            {
            };

            acquireTokenButton.Clicked       += browseButton_Clicked;
            acquireTokenSilentButton.Clicked += acquireTokenSilentButton_Clicked;
            conditionalAccessButton.Clicked  += conditionalAccessButton_Clicked;
            clearButton.Clicked += clearButton_Clicked;

            Content = new StackLayout
            {
                VerticalOptions = LayoutOptions.Center,
                Children        =
                {
                    acquireTokenButton,
                    acquireTokenSilentButton,
                    conditionalAccessButton,
                    clearButton,
                    result,
                    logLabel
                }
            };

            LoggerCallbackHandler.Callback = callback;
        }
Example #7
0
        public static async Task <AuthenticationResult> GetTokenSilentAsync(User user)
        {
            TokenBroker             brkr = new TokenBroker();
            PublicClientApplication app  =
                new PublicClientApplication("7c7a2f70-caef-45c8-9a6c-091633501de4");

            try
            {
                return(await app.AcquireTokenSilentAsync(brkr.Sts.ValidScope));
            }
            catch (Exception ex)
            {
                string msg = ex.Message + "\n" + ex.StackTrace;
                Console.WriteLine(msg);
                return(await app.AcquireTokenAsync(brkr.Sts.ValidScope, user.DisplayableId, UiOptions.ActAsCurrentUser, null));
            }
        }
Example #8
0
        public static async Task <AuthenticationResult> GetTokenInteractiveAsync()
        {
            try
            {
                TokenBroker             brkr = new TokenBroker();
                PublicClientApplication app  =
                    new PublicClientApplication("7c7a2f70-caef-45c8-9a6c-091633501de4");
                await app.AcquireTokenAsync(brkr.Sts.ValidScope);

                return(await app.AcquireTokenAsync(brkr.Sts.ValidScope));
            }
            catch (Exception ex)
            {
                string msg = ex.Message + "\n" + ex.StackTrace;
                Console.WriteLine(msg);
            }

            return(null);
        }
Example #9
0
 partial void UIButton11_TouchUpInside(UIButton sender)
 {
     try
     {
         ReportLabel.Text = string.Empty;
         TokenBroker tokenBroker = new TokenBroker();
         sts.Authority     = "https://login.microsoftonline.com/common";
         sts.ValidClientId = "CLIENT_ID";
         sts.ValidScope    = new[] { "SCOPE1" };
         sts.ValidUserName = "******";
         sts.ValidNonExistingRedirectUri = new Uri("APP-SCHEME//BUNDLE-ID");
         tokenBroker.Sts = sts;
         string token = null;// await tokenBroker.GetTokenInteractiveAsync(new PlatformParameters(this));
         ReportLabel.Text = token;
     }
     catch (Exception ex)
     {
         ReportLabel.Text = ex.Message;
     }
 }
Example #10
0
        async partial void UIButton16_TouchUpInside(UIButton sender)
        {
            try
            {
                ReportLabel.Text = string.Empty;
                TokenBroker tokenBroker = new TokenBroker();
                sts.Authority     = "https://login.microsoftonline.com/common";
                sts.ValidClientId = "<CLIENT_ID>";
                sts.ValidResource = "<RESOURCE>";
                sts.ValidUserName = "******";
                sts.ValidNonExistingRedirectUri = new Uri("REDIRECT_URI");
                tokenBroker.Sts = sts;
                string token = await tokenBroker.GetTokenInteractiveAsync(new PlatformParameters(this, false));

                ReportLabel.Text = token;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #11
0
        partial void UIButton30_TouchUpInside(UIButton sender)
        {
            TokenBroker tokenBroker = new TokenBroker();

            tokenBroker.ClearTokenCache();
        }
 public MainPage()
 {
     this.InitializeComponent();
     tokenBroker = new TokenBroker();
 }
        static void ClearCacheClicked(Object sender, EventArgs e)
        {
            var tokenBroker = new TokenBroker();

            tokenBroker.ClearTokenCache();
        }
Example #14
0
        partial void ClearCacheClicked(NSObject sender)
        {
            var tokenBroker = new TokenBroker();

            tokenBroker.ClearTokenCache();
        }