public async Task OnBehalfOfProvider_ShouldGetNewAccessTokenWithNoUserAssertion() { HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, "http://example.org/foo"); httpRequestMessage.Properties.Add(typeof(GraphRequestContext).ToString(), new GraphRequestContext { MiddlewareOptions = new Dictionary <string, IMiddlewareOption> { { typeof(AuthenticationHandlerOption).ToString(), new AuthenticationHandlerOption { AuthenticationProviderOption = new MsalAuthenticationProviderOption { UserAssertion = null } } } } }); AuthenticationResult expectedAuthResult = MockAuthResult.GetAuthenticationResult(new GraphAccount(_graphUserAccount)); _mockClientApplicationBase.Setup((cca) => cca.AcquireTokenOnBehalfOfAsync(_scopes, It.IsAny <UserAssertion>(), "common")) .ReturnsAsync(expectedAuthResult); OnBehalfOfProvider authProvider = new OnBehalfOfProvider(_mockClientApplicationBase.Object, _scopes); await authProvider.AuthenticateRequestAsync(httpRequestMessage); Assert.IsInstanceOfType(authProvider.ClientApplication, typeof(IConfidentialClientApplication), "Unexpected client application set."); Assert.IsNotNull(httpRequestMessage.Headers.Authorization, "Unexpected auhtorization header set."); Assert.AreEqual(expectedAuthResult.AccessToken, httpRequestMessage.Headers.Authorization.Parameter, "Unexpected access token set."); }
public async Task OnBehalfOfProvider_ShouldGetCachedAccessTokenForUserAssertion() { UserAssertion assertion = new UserAssertion(_jwtAccessToken); HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, "http://example.org/foo"); httpRequestMessage.Properties.Add(typeof(GraphRequestContext).ToString(), new GraphRequestContext { MiddlewareOptions = new Dictionary <string, IMiddlewareOption> { { typeof(AuthenticationHandlerOption).ToString(), new AuthenticationHandlerOption { AuthenticationProviderOption = new MsalAuthenticationProviderOption { UserAssertion = assertion } } } } }); OnBehalfOfProvider authProvider = new OnBehalfOfProvider(_mockClientApplicationBase.Object, _scopes); await authProvider.AuthenticateRequestAsync(httpRequestMessage); Assert.IsInstanceOfType(authProvider.ClientApplication, typeof(IConfidentialClientApplication), "Unexpected client application set."); Assert.IsNotNull(httpRequestMessage.Headers.Authorization, "Unexpected auhtorization header set."); Assert.AreEqual(_silentAuthResult.AccessToken, httpRequestMessage.Headers.Authorization.Parameter, "Unexpected access token set."); }