public AcquireTokenForClient ( string scope, string policy ) : Task |
||
scope | string | |
policy | string | |
리턴 | Task |
public void ConfidentialClientUsingSecretTest() { ConfidentialClientApplication app = new ConfidentialClientApplication(TestConstants.DefaultClientId, TestConstants.DefaultRedirectUri, new ClientCredential(TestConstants.DefaultClientSecret), new TokenCache()); app.AppTokenCache = new TokenCache(); HttpMessageHandlerFactory.MockHandler = new MockHttpMessageHandler() { Method = HttpMethod.Post, ResponseMessage = MockHelpers.CreateSuccessfulClientCredentialTokenResponseMessage() }; Task<AuthenticationResult> task = app.AcquireTokenForClient(TestConstants.DefaultScope.ToArray(), TestConstants.DefaultPolicy); AuthenticationResult result = task.Result; Assert.IsNotNull(result); Assert.IsNotNull("header.payload.signature", result.Token); Assert.AreEqual(TestConstants.DefaultScope.AsSingleString(), result.ScopeSet.AsSingleString()); //make sure user token cache is empty Assert.AreEqual(0, app.UserTokenCache.Count); //check app token cache count to be 1 Assert.AreEqual(1, app.AppTokenCache.Count); //make sure refresh token is null foreach (var value in app.AppTokenCache.tokenCacheDictionary.Values) { Assert.IsNull(value.RefreshToken); } }
public void ConfidentialClientUsingCertificateTest() { ClientCredential cc = new ClientCredential(new ClientAssertionCertificate(new X509Certificate2("valid_cert.pfx", "password"))); ConfidentialClientApplication app = new ConfidentialClientApplication(TestConstants.DefaultClientId, TestConstants.DefaultRedirectUri, cc, new TokenCache()); app.AppTokenCache = new TokenCache(); HttpMessageHandlerFactory.MockHandler = new MockHttpMessageHandler() { Method = HttpMethod.Post, ResponseMessage = MockHelpers.CreateSuccessfulClientCredentialTokenResponseMessage() }; Task<AuthenticationResult> task = app.AcquireTokenForClient(TestConstants.DefaultScope.ToArray(), TestConstants.DefaultPolicy); AuthenticationResult result = task.Result; Assert.IsNotNull(result); Assert.IsNotNull("header.payload.signature", result.Token); Assert.AreEqual(TestConstants.DefaultScope.AsSingleString(), result.ScopeSet.AsSingleString()); //make sure user token cache is empty Assert.AreEqual(0, app.UserTokenCache.Count); //check app token cache count to be 1 Assert.AreEqual(1, app.AppTokenCache.Count); //make sure refresh token is null foreach (var value in app.AppTokenCache.tokenCacheDictionary.Values) { Assert.IsNull(value.RefreshToken); } //assert client credential Assert.IsNotNull(cc.ClientAssertion); Assert.AreNotEqual(0, cc.ValidTo); //save client assertion. string cachedAssertion = cc.ClientAssertion.Assertion; long cacheValidTo = cc.ValidTo; HttpMessageHandlerFactory.MockHandler = new MockHttpMessageHandler() { Method = HttpMethod.Post, ResponseMessage = MockHelpers.CreateSuccessfulClientCredentialTokenResponseMessage() }; task = app.AcquireTokenForClient(TestConstants.ScopeForAnotherResource.ToArray(), TestConstants.DefaultPolicy); result = task.Result; Assert.IsNotNull(result); Assert.AreEqual(cacheValidTo, cc.ValidTo); Assert.AreEqual(cachedAssertion, cc.ClientAssertion.Assertion); }