Ejemplo n.º 1
0
        public void DuplicateQueryParameterErrorTest()
        {
            Authenticator authenticator = new Authenticator(TestConstants.DefaultAuthorityHomeTenant, false, Guid.NewGuid());

            HandlerData data = new HandlerData()
            {
                Authenticator        = authenticator,
                ClientKey            = new ClientKey(TestConstants.DefaultClientId),
                Policy               = TestConstants.DefaultPolicy,
                RestrictToSingleUser = TestConstants.DefaultRestrictToSingleUser,
                Scope      = TestConstants.DefaultScope.ToArray(),
                TokenCache = null
            };

            AcquireTokenInteractiveHandler handler = new AcquireTokenInteractiveHandler(data,
                                                                                        TestConstants.ScopeForAnotherResource.ToArray(),
                                                                                        new Uri("some://uri"), new PlatformParameters(),
                                                                                        (User)null, UiOptions.ForceLogin, "extra=qp&prompt=login", new MockWebUI());

            handler.PreRunAsync().Wait();

            try
            {
                handler.PreTokenRequest().Wait();
                Assert.Fail("MsalException should be thrown here");
            }
            catch (Exception exc)
            {
                Assert.IsTrue(exc.InnerException is MsalException);
                Assert.AreEqual(MsalError.DuplicateQueryParameter, ((MsalException)exc.InnerException).ErrorCode);
            }
        }
Ejemplo n.º 2
0
        public void VerifyAuthorizationResultTest()
        {
            Authenticator authenticator = new Authenticator(TestConstants.DefaultAuthorityHomeTenant, false, Guid.NewGuid());

            MockWebUI webUi = new MockWebUI();

            webUi.MockResult = new AuthorizationResult(AuthorizationStatus.ErrorHttp,
                                                       TestConstants.DefaultAuthorityHomeTenant + "?error=" + OAuthError.LoginRequired);

            HandlerData data = new HandlerData()
            {
                Authenticator        = authenticator,
                ClientKey            = new ClientKey(TestConstants.DefaultClientId),
                Policy               = TestConstants.DefaultPolicy,
                RestrictToSingleUser = TestConstants.DefaultRestrictToSingleUser,
                Scope      = TestConstants.DefaultScope.ToArray(),
                TokenCache = null
            };

            AcquireTokenInteractiveHandler handler = new AcquireTokenInteractiveHandler(data,
                                                                                        TestConstants.ScopeForAnotherResource.ToArray(), new Uri("some://uri"), new PlatformParameters(),
                                                                                        (string)null, UiOptions.ForceLogin, "extra=qp", webUi);

            handler.PreRunAsync().Wait();
            try
            {
                handler.PreTokenRequest().Wait();
                Assert.Fail("MsalException should have been thrown here");
            }
            catch (Exception exc)
            {
                Assert.IsTrue(exc.InnerException is MsalException);
                Assert.AreEqual(MsalError.UserInteractionRequired, ((MsalException)exc.InnerException).ErrorCode);
            }


            webUi            = new MockWebUI();
            webUi.MockResult = new AuthorizationResult(AuthorizationStatus.ErrorHttp,
                                                       TestConstants.DefaultAuthorityHomeTenant + "?error=invalid_request&error_description=some error description");

            handler = new AcquireTokenInteractiveHandler(data,
                                                         TestConstants.ScopeForAnotherResource.ToArray(), new Uri("some://uri"), new PlatformParameters(),
                                                         (string)null, UiOptions.ForceLogin, "extra=qp", webUi);
            handler.PreRunAsync().Wait();

            try
            {
                handler.PreTokenRequest().Wait();
                Assert.Fail("MsalException should have been thrown here");
            }
            catch (Exception exc)
            {
                Assert.IsTrue(exc.InnerException is MsalException);
                Assert.AreEqual("invalid_request", ((MsalException)exc.InnerException).ErrorCode);
                Assert.AreEqual("some error description", ((MsalException)exc.InnerException).Message);
            }
        }
Ejemplo n.º 3
0
        public void ActAsCurrentUserNoSsoHeaderForLoginHintOnlyTest()
        {
            //this test validates that no SSO header is added when developer passes only login hint and UiOption.ActAsCurrentUser
            Authenticator authenticator = new Authenticator(TestConstants.DefaultAuthorityHomeTenant, false, Guid.NewGuid());
            TokenCache    cache         = new TokenCache();
            TokenCacheKey key           = new TokenCacheKey(TestConstants.DefaultAuthorityHomeTenant,
                                                            TestConstants.DefaultScope, TestConstants.DefaultClientId,
                                                            TestConstants.DefaultUniqueId, TestConstants.DefaultDisplayableId, TestConstants.DefaultHomeObjectId,
                                                            TestConstants.DefaultPolicy);
            AuthenticationResultEx ex = new AuthenticationResultEx();

            ex.Result = new AuthenticationResult("Bearer", key.ToString(),
                                                 new DateTimeOffset(DateTime.UtcNow + TimeSpan.FromSeconds(3599)));
            ex.Result.User = new User
            {
                DisplayableId = TestConstants.DefaultDisplayableId,
                UniqueId      = TestConstants.DefaultUniqueId,
                HomeObjectId  = TestConstants.DefaultHomeObjectId
            };
            ex.Result.FamilyId = "1";
            ex.RefreshToken    = "someRT";
            cache.tokenCacheDictionary[key] = ex;

            MockWebUI webUi = new MockWebUI();

            webUi.MockResult = new AuthorizationResult(AuthorizationStatus.Success,
                                                       TestConstants.DefaultAuthorityHomeTenant + "?code=some-code");

            HandlerData data = new HandlerData()
            {
                Authenticator        = authenticator,
                ClientKey            = new ClientKey(TestConstants.DefaultClientId),
                Policy               = TestConstants.DefaultPolicy,
                RestrictToSingleUser = TestConstants.DefaultRestrictToSingleUser,
                Scope      = TestConstants.DefaultScope.ToArray(),
                TokenCache = cache
            };

            AcquireTokenInteractiveHandler handler = new AcquireTokenInteractiveHandler(data,
                                                                                        TestConstants.ScopeForAnotherResource.ToArray(),
                                                                                        new Uri("some://uri"), new PlatformParameters(),
                                                                                        ex.Result.User, UiOptions.ActAsCurrentUser, "extra=qp", webUi);

            handler.PreRunAsync().Wait();
            handler.PreTokenRequest().Wait();
        }