コード例 #1
0
 internal EncompassApiClient(IClientParameters parameters, IEncompassApiClient encompassApiService)
 {
     _encompassApiSerice          = encompassApiService;
     ApiResponse                  = parameters.ApiResponse;
     CommonCache                  = (parameters.CommonCache ??= new CommonCache());
     UndefinedCustomFieldHandling = parameters.UndefinedCustomFieldHandling;
 }
コード例 #2
0
        public EncompassApiService(HttpClient httpClient, IClientParameters parameters)
        {
            _httpClient       = httpClient;
            _clientParameters = parameters;

            ApiResponse = parameters.ApiResponse;
            CommonCache = parameters.CommonCache ?? (parameters.CommonCache = new CommonCache());
            UndefinedCustomFieldHandling = parameters.UndefinedCustomFieldHandling;
        }
コード例 #3
0
 public IClient CreateClient(ConnectionProviderType type, IClientParameters parameters)
 {
     if (type == ConnectionProviderType.DotNet)
     {
         return(new DotNetClient(GetLocalEndPoint(), parameters));
     }
     else if (type == ConnectionProviderType.Mono)
     {
         return(new MonoClient(GetLocalEndPoint(), parameters));
     }
     throw new NotSupportedException();
 }
コード例 #4
0
        /// <summary>
        /// Creates a client object from an existing access token.
        /// </summary>
        /// <param name="parameters">The parameters to initialize the client object with.</param>
        /// <param name="accessToken">The access token to use.</param>
        /// <param name="cancellationToken">The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None"/>.</param>
        /// <returns></returns>
        public static async Task <EncompassApiClient> CreateFromAccessTokenAsync(IClientParameters parameters, string accessToken, CancellationToken cancellationToken = default)
        {
            throw new NotImplementedException();
            Preconditions.NotNull(parameters, nameof(parameters));
            Preconditions.NotNullOrEmpty(accessToken, nameof(accessToken));

            //TODO HttpClient Private Method setup
            var client = new EncompassApiClient(parameters, new EncompassApiService(new HttpClient(), parameters));

            //removed token initialization
            return(client);
        }
コード例 #5
0
        /// <summary>
        /// Creates a client object from user credentials. It does not automatically retrieve a new token when the current one expires so most of the time you'll probably want to use the CreateAsync method instead.
        /// </summary>
        /// <param name="parameters">The parameters to initialize the client object with.</param>
        /// <param name="instanceId">The encompass instance id.</param>
        /// <param name="userId">The encompass user id.</param>
        /// <param name="password">The encompass user password.</param>
        /// <param name="cancellationToken">The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None"/>.</param>
        /// <returns></returns>
        public static async Task <EncompassApiClient> CreateFromUserCredentialsAsync(IClientParameters parameters, string instanceId, string userId, string password, CancellationToken cancellationToken = default)
        {
            Preconditions.NotNull(parameters, nameof(parameters));
            Preconditions.NotNullOrEmpty(instanceId, nameof(instanceId));
            Preconditions.NotNullOrEmpty(userId, nameof(userId));
            Preconditions.NotNullOrEmpty(password, nameof(password));

            var encompassTokenClientOptions = new EncompassTokenClientOptions
            {
                BaseUrl             = parameters.BaseAddress,
                ClientId            = parameters.ApiClientId,
                ClientSecret        = parameters.ApiClientSecret,
                EncompassInstanceId = instanceId,
                ClientName          = "EncompassTokenClient",
                Password            = password,
                Username            = userId,
                Retry            = true,
                RetryCount       = 3,
                TimeoutInSeconds = 30
            };

            IOptions <EncompassTokenClientOptions> options = Options.Create(encompassTokenClientOptions);

            var retryPolicy   = HttpPolicyExtensions.HandleTransientHttpError().RetryAsync(parameters.TimeoutRetryCount);
            var timeoutPolicy = Policy.TimeoutAsync <HttpResponseMessage>(parameters.Timeout);

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddSingleton(options);

            serviceCollection.AddHttpClient(encompassTokenClientOptions.ClientName)
            .AddPolicyHandler(HttpPolicyExtensions.HandleTransientHttpError().RetryAsync(parameters.TimeoutRetryCount))
            .AddPolicyHandler(Policy.TimeoutAsync <HttpResponseMessage>(parameters.Timeout));

            serviceCollection.AddScoped <ITokenClient>(sp => new EncompassTokenClient(sp.GetService <IHttpClientFactory>().CreateClient("EncompassTokenClient"), options));

            serviceCollection.AddHttpClient("EncompassClient")
            .AddPolicyHandler(HttpPolicyExtensions.HandleTransientHttpError().RetryAsync(parameters.TimeoutRetryCount))
            .AddPolicyHandler(Policy.TimeoutAsync <HttpResponseMessage>(parameters.Timeout))
            .AddHttpMessageHandler(sp => new TokenHandler(sp.GetService <ITokenClient>()));

            var serviceProvider = serviceCollection.BuildServiceProvider();

            var httpClientFactory = serviceProvider.GetService <IHttpClientFactory>();
            var client            = new EncompassApiClient(parameters, new EncompassApiService(httpClientFactory.CreateClient("EncompassHttpClient"), parameters));

            return(client);
        }
コード例 #6
0
        public static Client Mvc(this IClientParameters clientParameters)
        {
            var client = new Client
            {
                ClientName          = clientParameters.DisplayName,
                ClientId            = clientParameters.Name,
                AllowedGrantTypes   = GrantTypes.Hybrid,
                AccessTokenType     = AccessTokenType.Reference,
                AccessTokenLifetime = 120,
                AllowOfflineAccess  = true,
                UpdateAccessTokenClaimsOnRefresh = true,
                RedirectUris           = { $"{clientParameters.Authority}/signin-oidc", },
                PostLogoutRedirectUris = { $"{clientParameters.Authority}/signout-callback-oidc", },
                AllowedScopes          =
                {
                    IdentityServerConstants.StandardScopes.OpenId,
                    IdentityServerConstants.StandardScopes.Profile,
                    IdentityServerConstants.StandardScopes.Address,
                },
                ClientSecrets =
                {
                    new Secret(clientParameters.Secret.Sha256()),
                },
            };

            foreach (var apiName in clientParameters.ApisNames)
            {
                client.AllowedScopes.Add(apiName);
            }

            foreach (var resource in clientParameters.Resources)
            {
                client.AllowedScopes.Add(resource.Name);
            }

            return(client);
        }
コード例 #7
0
ファイル: DotNetClient.cs プロジェクト: baulig/new-tls
 public DotNetClient(ClientFactory factory, IPEndPoint endpoint, IClientParameters parameters)
     : base(factory, endpoint, parameters)
 {
 }
コード例 #8
0
ファイル: MonoClient.cs プロジェクト: baulig/new-tls
 public MonoClient(IPEndPoint endpoint, IClientParameters parameters)
     : base(endpoint, parameters)
 {
 }
コード例 #9
0
 public override IClient CreateClient(IClientParameters parameters)
 {
     return(new MonoClient(this, EndPoint, parameters));
 }
コード例 #10
0
ファイル: DotNetClient.cs プロジェクト: baulig/new-tls
 public DotNetClient(IPEndPoint endpoint, IClientParameters parameters)
     : base(endpoint, parameters)
 {
 }
コード例 #11
0
 internal EncompassApiClient(IClientParameters parameters)
 {
     ApiResponse = parameters.ApiResponse;
     CommonCache = (parameters.CommonCache ??= new CommonCache());
     UndefinedCustomFieldHandling = parameters.UndefinedCustomFieldHandling;
 }
コード例 #12
0
        public static async Task <EncompassApiClient> CreateFromClientCredentialsAsync(IClientParameters parameters, string instanceId, CancellationToken cancellationToken = default)
        {
            Preconditions.NotNull(parameters, nameof(parameters));
            Preconditions.NotNullOrEmpty(instanceId, nameof(instanceId));

            //TODO HttpClient Private Method setup
            var client = new EncompassApiClient(parameters, new EncompassApiService(new HttpClient(), parameters));

            //removed token initialization
            return(client);
        }
コード例 #13
0
        public static void AddCustomClientAuthentication(this IServiceCollection services, IClientParameters clientParameters, string idPAuthority) =>
        services.AddAuthentication(options =>
        {
            options.DefaultScheme          = CookieAuthenticationDefaults.AuthenticationScheme;
            options.DefaultChallengeScheme = IdentityServerConstants.ProtocolTypes.OpenIdConnect;
        }).AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, (options) => options.AccessDeniedPath = "/AccessDenied")
        .AddOpenIdConnect(IdentityServerConstants.ProtocolTypes.OpenIdConnect, options =>
        {
            options.Authority  = idPAuthority;
            options.ClientId   = clientParameters.Name;
            options.SaveTokens = true;
            options.GetClaimsFromUserInfoEndpoint = true;
            options.ClientSecret = clientParameters.Secret;
            options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            options.ResponseType = CustomIdentityOptions.ResponseType;
            options.Scope.Add(IdentityServerConstants.StandardScopes.OpenId);
            options.Scope.Add(IdentityServerConstants.StandardScopes.OfflineAccess);
            options.Scope.Add(IdentityServerConstants.StandardScopes.Profile);
            options.Scope.Add(IdentityServerConstants.StandardScopes.Address);
            foreach (var apiName in clientParameters.ApisNames)
            {
                options.Scope.Add(apiName);
            }

            foreach (var resource in clientParameters.Resources)
            {
                options.Scope.Add(resource.Name);
            }

            options.ClaimActions.Remove(CustomIdentityOptions.Amr);
            options.ClaimActions.DeleteClaim(CustomIdentityOptions.Sid);
            options.ClaimActions.DeleteClaim(CustomIdentityOptions.Idp);
            foreach (var resource in clientParameters.Resources)
            {
                foreach (var claim in resource.ClaimTypes)
                {
                    options.ClaimActions.MapUniqueJsonKey(claim, claim);
                }
            }

            options.TokenValidationParameters = new TokenValidationParameters
            {
                NameClaimType = JwtClaimTypes.GivenName,
                RoleClaimType = JwtClaimTypes.Role,
            };
        });
コード例 #14
0
 public abstract IClient CreateClient(IClientParameters parameters);