Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Auth0TokenProvider" /> class.
 /// </summary>
 /// <param name="defaultSettings">The settings.</param>
 /// <param name="autoScheduler">The auto-scheduler that refreshes the Auth0 token after X minutes.</param>
 public Auth0TokenProvider(ILoggerFactory loggerFactory, Auth0ClientSettings defaultSettings,
                           IAuthenticationApiClient authenticationApiClient = null, IAutoScheduler autoScheduler = null)
     : base(loggerFactory, defaultSettings, authenticationApiClient)
 {
     this.autoScheduler = autoScheduler ?? new AutoScheduler(loggerFactory, this);
     defaultPassword    = defaultSettings.Auth0Password;
     defaultUsername    = defaultSettings.Auth0Username;
     defaultConnection  = defaultSettings.Auth0Connection;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="Auth0TokenProvider" /> class.
 /// </summary>
 /// <param name="defaultSettings">The settings.</param>
 /// <param name="autoScheduler">The auto-scheduler that refreshes the Auth0 token after X minutes.</param>
 public Auth0TokenProvider(ILoggerFactory loggerFactory, Auth0ClientSettings defaultSettings,
     IAuthenticationApiClient authenticationApiClient = null, IAutoScheduler autoScheduler = null)
     : base(loggerFactory, defaultSettings, authenticationApiClient)
 {
     this.autoScheduler = autoScheduler ?? new AutoScheduler(loggerFactory, this);
     defaultPassword = defaultSettings.Auth0Password;
     defaultUsername = defaultSettings.Auth0Username;
     defaultConnection = defaultSettings.Auth0Connection;
 }
Exemplo n.º 3
0
        public BasicAuthAuth0ProxyMiddleware(RequestDelegate next, BasicAuthAuth0ProxyConfig config)
        {
            _next   = next;
            _config = config;

            _policy = Policy.Handle <Exception>()
                      .WaitAndRetryAsync(3, r => TimeSpan.FromSeconds(r));

            _auth0 = new AuthenticationApiClientCachingDecorator(new AuthenticationApiClient($"{_config.Domain}"));
        }
Exemplo n.º 4
0
 protected BaseAuth0TokenProvider(ILoggerFactory loggerFactory, Auth0ClientSettings defaultSettings, IAuthenticationApiClient authenticationApiClient)
 {
     this.authenticationApiClient = authenticationApiClient ?? new AuthenticationApiClient();
     clientTokenCache             = new ConcurrentDictionary <string, Auth0ClientSettings>();
     domainClientIdCache          = new ConcurrentDictionary <string, string>();
     logger                  = loggerFactory.CreateLogger <BaseAuth0TokenProvider>();
     defaultDomain           = defaultSettings.Auth0ServerUrl;
     defaultRefreshToken     = defaultSettings.Auth0RefreshToken;
     defaultAutoRefreshAfter = defaultSettings.AutoRefreshAfter;
 }
 protected BaseAuth0TokenProvider(ILoggerFactory loggerFactory, Auth0ClientSettings defaultSettings, IAuthenticationApiClient authenticationApiClient)
 {
     this.authenticationApiClient = authenticationApiClient ?? new AuthenticationApiClient();
     clientTokenCache = new ConcurrentDictionary<string, Auth0ClientSettings>();
     domainClientIdCache = new ConcurrentDictionary<string, string>();
     logger = loggerFactory.CreateLogger<BaseAuth0TokenProvider>();
     defaultDomain = defaultSettings.Auth0ServerUrl;
     defaultRefreshToken = defaultSettings.Auth0RefreshToken;
     defaultAutoRefreshAfter = defaultSettings.AutoRefreshAfter;
 }
        public AuthenticationApiClientCachingDecorator(IAuthenticationApiClient inner)
        {
            _inner = inner;
            _accessTokenResponseCachePolicy = Policy.CacheAsync(
                _memoryCacheProvider.AsyncFor <AccessTokenResponse>(),
                new ResultTtl <AccessTokenResponse>(r => new Ttl(_expiresIn(r), false)));

            _userInfoCachePolicy = Policy.CacheAsync(
                _memoryCacheProvider.AsyncFor <UserInfo>(),
                new ContextualTtl());
        }
Exemplo n.º 7
0
        public TokenProvider(IFtpClientProxyConfig config)
        {
            _config = config;

            if (_config.UseAuth0)
            {
                _auth0 = new AuthenticationApiClientCachingDecorator(new AuthenticationApiClient(_config.TenantID));
            }
            else
            {
                _adal = new AuthenticationContext("https://login.microsoftonline.com/" + this._config.TenantID);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="Auth0TokenProvider" /> class.
 /// </summary>
 /// <param name="loggerFactory">The logger factory.</param>
 /// <param name="defaultSettings">The settings.</param>
 /// <param name="authenticationApiClient">The optional AuthenticationApiClient to use. Usually not required to use the built-in client.</param>
 /// <param name="autoScheduler">The auto-scheduler that refreshes the Auth0 token after X minutes.</param>
 public Auth0TokenProvider(ILoggerFactory loggerFactory, Auth0ClientSettings defaultSettings, IAuthenticationApiClient authenticationApiClient = null, IAutoScheduler autoScheduler = null)
 {
     this.autoScheduler           = autoScheduler ?? new AutoScheduler(loggerFactory, this);
     this.authenticationApiClient = authenticationApiClient ?? new AuthenticationApiClient();
     clientTokenCache             = new ConcurrentDictionary <string, Auth0ClientSettings>();
     domainClientIdCache          = new ConcurrentDictionary <string, string>();
     logger                  = loggerFactory.CreateLogger <Auth0TokenProvider>();
     defaultDomain           = defaultSettings.Auth0ServerUrl;
     defaultPassword         = defaultSettings.Auth0Password;
     defaultUsername         = defaultSettings.Auth0Username;
     defaultConnection       = defaultSettings.Auth0Connection;
     defaultRefreshToken     = defaultSettings.Auth0RefreshToken;
     defaultAutoRefreshAfter = defaultSettings.AutoRefreshAfter;
 }
Exemplo n.º 9
0
        public FtpClientProxy(IFtpClientProxyConfig config, IFlurlClientFactory client, string host, NetworkCredential credentials)
        {
            this._config     = config;
            this.Host        = host;
            this.Credentials = credentials;

            _client = client.Get(_config.FtpProxyWebInterfaceBaseUri)
                      .Configure(c =>
            {
                c.HttpClientFactory      = new UntrustedCertClientFactory();
                c.ConnectionLeaseTimeout = TimeSpan.FromMinutes(30);
            })
                      .WithHeader("Accept", "application/json, text/json")
                      .WithHeader("Accept-Encoding", "gzip, deflate")
                      .WithTimeout(TimeSpan.FromMinutes(20))
                      .AllowHttpStatus(HttpStatusCode.NotFound)
            ;

            _client.BaseUrl = _config.FtpProxyWebInterfaceBaseUri.ToString();

            if (_config.UseAuth0)
            {
                _auth0 = new AuthenticationApiClientCachingDecorator(new AuthenticationApiClient(_config.TenantID));
            }
            else
            {
                _adal = new AuthenticationContext("https://login.microsoftonline.com/" + this._config.TenantID);
            }

            _connectionInfo = new ConnectionInfo
            {
                Host     = this.Host,
                Username = this.Credentials.UserName,
                Password = this.Credentials.Password,
            };
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="Auth0v2TokenProvider" /> class.
 /// </summary>
 /// <param name="defaultSettings">The settings.</param>
 /// <param name="autoScheduler">The auto-scheduler that refreshes the Auth0 token after X minutes.</param>
 public Auth0v2TokenProvider(ILoggerFactory loggerFactory, Auth0ClientSettings defaultSettings, IAuthenticationApiClient authenticationApiClient = null, IAutoScheduler autoScheduler = null) : base(loggerFactory, defaultSettings, authenticationApiClient)
 {
     this.autoScheduler = autoScheduler ?? new AutoScheduler(loggerFactory, this);
     defaultClientSecret = defaultSettings.Auth0ClientSecret;
     defaultAudience = defaultSettings.Auth0Audience;
 }
 /// <summary>
 /// Creates a <see cref="WsFedUrlBuilder" /> for building a WS-Federation authentication URL.
 /// </summary>
 /// <param name="client"><see cref="IAuthenticationApiClient"/> capable of providing the Base URL.</param>
 /// <returns>A new <see cref="WsFedUrlBuilder" /> configured for this baseUrl.</returns>
 public static WsFedUrlBuilder BuildWsFedUrl(this IAuthenticationApiClient client)
 {
     return(new WsFedUrlBuilder(client.BaseUri));
 }
 /// <summary>
 /// Creates a <see cref="SamlUrlBuilder" /> for building a SAML authentication URL.
 /// </summary>
 /// <param name="client"><see cref="IAuthenticationApiClient"/> capable of providing the Base URL.</param>
 /// <param name="clientId">ID of the client.</param>
 /// <returns>A new <see cref="SamlUrlBuilder" /> configured for this baseUrl and <paramref name="client"/>.</returns>
 public static SamlUrlBuilder BuildSamlUrl(this IAuthenticationApiClient client, string clientId)
 {
     return(new SamlUrlBuilder(client.BaseUri, clientId));
 }
 /// <summary>
 /// Creates a <see cref="LogoutUrlBuilder" /> for building a logout URL.
 /// </summary>
 /// <param name="client"><see cref="IAuthenticationApiClient"/> capable of providing the Base URL.</param>
 /// <returns>A new <see cref="LogoutUrlBuilder" /> configured for this baseUrl.</returns>
 public static LogoutUrlBuilder BuildLogoutUrl(this IAuthenticationApiClient client)
 {
     return(new LogoutUrlBuilder(client.BaseUri));
 }
 /// <summary>
 /// Creates a <see cref="AuthorizationUrlBuilder" /> for building an authorization URL.
 /// </summary>
 /// <param name="client"><see cref="IAuthenticationApiClient"/> capable of providing the Base URL.</param>
 /// <returns>A new <see cref="AuthorizationUrlBuilder" /> configured for this baseUrl.</returns>
 public static AuthorizationUrlBuilder BuildAuthorizationUrl(this IAuthenticationApiClient client)
 {
     return(new AuthorizationUrlBuilder(client.BaseUri));
 }
Exemplo n.º 15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Auth0v2TokenProvider" /> class.
 /// </summary>
 /// <param name="defaultSettings">The settings.</param>
 /// <param name="autoScheduler">The auto-scheduler that refreshes the Auth0 token after X minutes.</param>
 public Auth0v2TokenProvider(ILoggerFactory loggerFactory, Auth0ClientSettings defaultSettings, IAuthenticationApiClient authenticationApiClient = null, IAutoScheduler autoScheduler = null) : base(loggerFactory, defaultSettings, authenticationApiClient)
 {
     this.autoScheduler  = autoScheduler ?? new AutoScheduler(loggerFactory, this);
     defaultClientSecret = defaultSettings.Auth0ClientSecret;
     defaultAudience     = defaultSettings.Auth0Audience;
 }