Esempio n. 1
0
        public void SSOModeTest()
        {
            AuthenticationContextProxy.SetCredentials(null, Sts.ValidPassword);
            var context = new AuthenticationContextProxy(Sts.Authority, Sts.ValidateAuthority);
            AuthenticationResultProxy result = context.AcquireToken(Sts.ValidResource, Sts.ValidClientId, Sts.ValidDefaultRedirectUri, PromptBehaviorProxy.Auto, Sts.ValidUserId);

            AdalTests.VerifySuccessResult(Sts, result);

            AuthenticationContextProxy.ClearDefaultCache();

            AuthenticationContextProxy.SetCredentials(Sts.ValidUserName, Sts.ValidPassword);
            result = context.AcquireToken(Sts.ValidResource, Sts.ValidClientId, null);
            AdalTests.VerifySuccessResult(Sts, result);

            AuthenticationContextProxy.ClearDefaultCache();

            result = context.AcquireToken(Sts.ValidResource, Sts.ValidClientId, null);
            AdalTests.VerifySuccessResult(Sts, result);

            AuthenticationContextProxy.ClearDefaultCache();

            result = context.AcquireToken(Sts.ValidResource, Sts.ValidClientId,
                                          new Uri("ms-app://s-1-15-2-2097830667-3131301884-2920402518-3338703368-1480782779-4157212157-3811015497/"));
            AdalTests.VerifyErrorResult(result, Sts.InvalidArgumentError, "return URI");
        }
Esempio n. 2
0
        public void AcquireTokenWithPromptBehaviorNeverTestAsync()
        {
            // TODO: Not fully working at this point due to session cookies being deleted between WAB calls.

            Sts sts = Sts;

            // Should not be able to get a token silently passing redirectUri.
            var context = new AuthenticationContextProxy(sts.Authority, sts.ValidateAuthority);
            AuthenticationResultProxy result = context.AcquireToken(sts.ValidResource, sts.ValidClientId, sts.ValidDefaultRedirectUri, PromptBehaviorProxy.Never);

            AdalTests.VerifyErrorResult(result, Sts.InvalidArgumentError, "SSO");

            AuthenticationContextProxy.SetCredentials(sts.ValidUserName, sts.ValidPassword);
            result = context.AcquireToken(sts.ValidResource, sts.ValidClientId, sts.ValidDefaultRedirectUri);
            AdalTests.VerifySuccessResult(sts, result);

            AuthenticationContextProxy.ClearDefaultCache();
            result = context.AcquireToken(sts.ValidResource, sts.ValidClientId, sts.ValidDefaultRedirectUri);
            AdalTests.VerifySuccessResult(sts, result);

            // Should not be able to get a token silently on first try.
            result = context.AcquireToken(sts.ValidResource, sts.ValidClientId, null, PromptBehaviorProxy.Never);
            AdalTests.VerifyErrorResult(result, Sts.UserInteractionRequired, null);

            AuthenticationContextProxy.SetCredentials(sts.ValidUserName, sts.ValidPassword);
            // Obtain a token interactively.
            result = context.AcquireToken(sts.ValidResource, sts.ValidClientId, null);
            AdalTests.VerifySuccessResult(sts, result);

            // Obtain a token interactively.
            AuthenticationContextProxy.ClearDefaultCache();
            result = context.AcquireToken(sts.ValidResource, sts.ValidClientId, null);
            AdalTests.VerifySuccessResult(sts, result);

            AuthenticationContextProxy.SetCredentials(null, null);
            // Now there should be a token available in the cache so token should be available silently.
            result = context.AcquireToken(sts.ValidResource, sts.ValidClientId, null, PromptBehaviorProxy.Never);
            AdalTests.VerifySuccessResult(sts, result);

            // Clear the cache and silent auth should work via session cookies.
            AuthenticationContextProxy.ClearDefaultCache();
            result = context.AcquireToken(sts.ValidResource, sts.ValidClientId, null, PromptBehaviorProxy.Never);
            AdalTests.VerifySuccessResult(sts, result);

            // Clear the cache and cookies and silent auth should fail.
            AuthenticationContextProxy.ClearDefaultCache();
            AdalTests.EndBrowserDialogSession();
            result = context.AcquireToken(sts.ValidResource, sts.ValidClientId, null, PromptBehaviorProxy.Never);
            AdalTests.VerifyErrorResult(result, Sts.UserInteractionRequired, null);
        }