Ejemplo n.º 1
0
        /// <summary>
        /// Create an IAccessApiFactory using the specified Url and Token Provider
        /// </summary>
        public static IAccessApiFactory Build(string url, ITokenProvider tokenProvider)
        {
            // TokenProviderConfiguration.ApiClient is the client used by AccessApiFactory and is
            // NOT thread-safe, so there needs to be a separate instance for each instance of AccessApiFactory.
            // Do NOT cache the AccessApiFactory instances (DEV-6922)
            var config = new TokenProviderConfiguration(tokenProvider)
            {
                BasePath = url
            };

            return(new AccessApiFactory(config));
        }
        public void CanUseTokenProviderConfiguration()
        {
            var mockTokenProvider = new Mock <ITokenProvider>(MockBehavior.Loose);  // Don't care about the response

            // GIVEN a TokenProviderConfiguration configured with a mock TokenProvider
            TokenProviderConfiguration config = new TokenProviderConfiguration(mockTokenProvider.Object);

            // BEFORE the token is requested
            // THEN TokenProvider should not have been called
            mockTokenProvider.Verify(x => x.GetAuthenticationTokenAsync(), Times.Never);

            // WHEN the token is requested
            // THEN TokenProvider should not have been called each time
            var _ = config.AccessToken;

            mockTokenProvider.Verify(x => x.GetAuthenticationTokenAsync(), Times.Once);

            var __ = config.AccessToken;

            mockTokenProvider.Verify(x => x.GetAuthenticationTokenAsync(), Times.Exactly(2));
        }
Ejemplo n.º 3
0
 public static void Logout(this HttpResponseBase response, TokenProviderConfiguration configuration, string redirectUrl)
 {
     HttpContext.Current.GetOwinContext().Authentication.SignOut(configuration.Policy);
     HttpContext.Current.GetOwinContext().Authentication.SignOut(CookieAuthenticationDefaults.AuthenticationType);
     response.Redirect(redirectUrl);
 }
Ejemplo n.º 4
0
 private AdditionalScopeHandler(IServiceProvider appApplicationServices, TokenProviderConfiguration configuration)
 {
     _configuration = configuration;
 }
Ejemplo n.º 5
0
 private AdditionalScopeHandler(TokenProviderConfiguration configuration)
 {
     _configuration = configuration;
 }
Ejemplo n.º 6
0
 public static string Authority(TokenProviderConfiguration configuration) => $"https://login.microsoftonline.com/tfp/{configuration.TenantId}/{configuration.Policy}/v2.0/.well-known/openid-configuration";
Ejemplo n.º 7
0
 public CustomHttpHandler(TokenProviderConfiguration config, ITokenHandler handler)
 {
     _config  = config;
     _handler = handler;
 }
Ejemplo n.º 8
0
 public IndexModel(ITokenHandler tokenHandler, TokenProviderConfiguration config)
 {
     _tokenHandler = tokenHandler;
     _config       = config;
     _client       = new HttpClient(new CustomHttpHandler(config, tokenHandler));
 }
 private OauthAttribute(ITokenHandler iOAuthTokenProvider, TokenProviderConfiguration tokenProviderConfiguration)
 {
     _provider = iOAuthTokenProvider;
     _tokenProviderConfiguration = tokenProviderConfiguration;
 }