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

            Console.WriteLine(token);
        }
示例#2
0
        public static async Task <AuthenticationResult> GetTokenSilentAsync(User user)
        {
            TokenBroker             brkr = new TokenBroker();
            PublicClientApplication app  =
                new PublicClientApplication("269da09d-a3e8-4b9e-b0a3-18fdf67d7507");

            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));
            }
        }
示例#3
0
        public static async Task <AuthenticationResult> GetTokenInteractiveAsync()
        {
            try
            {
                TokenBroker             brkr = new TokenBroker();
                PublicClientApplication app  =
                    new PublicClientApplication("269da09d-a3e8-4b9e-b0a3-18fdf67d7507");
                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);
        }