Example #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services
            .AddTokenAuthentication(Configuration)
            .AddAuthorization()
            .AddControllers()
            .AddJsonOptions(o =>
            {
                o.JsonSerializerOptions.WriteIndented = true;
            });

            services.AddRouting(r => r.LowercaseUrls = true);

#if DEBUG
            // Register the Swagger generator, defining 1 or more Swagger documents
            // https://docs.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-3.1&tabs=visual-studio
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo
                {
                    Title       = "CertifyServer - Certificate Server API",
                    Version     = "v1",
                    Description = "CertifyServer provides a certificate services API for use in devops, CI/CD, middleware etc. Certificates are managed by Certify The Web on the primary server using ACME, with API access controlled using API tokens."
                });

                // declare authorization method
                c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
                {
                    Description  = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
                    Name         = "Authorization",
                    Scheme       = "bearer",
                    BearerFormat = "JWT",
                    In           = ParameterLocation.Header,
                    Type         = SecuritySchemeType.Http
                });

                // set security requirement
                c.AddSecurityRequirement(new OpenApiSecurityRequirement
                {
                    {
                        new OpenApiSecurityScheme
                        {
                            Reference = new OpenApiReference
                            {
                                Type = ReferenceType.SecurityScheme,
                                Id   = "Bearer"
                            }
                        }, new List <string>()
                    }
                });
            });
#endif
            // connect to certify service
            var configManager           = new ServiceConfigManager();
            var defaultConnectionConfig = new Shared.ServerConnection(configManager.GetServiceConfig());
            var connections             = ServerConnectionManager.GetServerConnections(null, defaultConnectionConfig);
            var serverConnection        = connections.FirstOrDefault(c => c.IsDefault = true);

            services.AddSingleton(typeof(Certify.Client.ICertifyInternalApiClient), new Client.CertifyApiClient(configManager, serverConnection));
        }
Example #2
0
        public CertifyApiClient(Shared.ServerConnection config = null)
        {
            _connectionConfig = config ?? GetDefaultServerConnection();

            _baseUri = $"{(_connectionConfig.UseHTTPS ? "https" : "http")}://{_connectionConfig.Host}:{_connectionConfig.Port}" + _baseUri;

#pragma warning disable SCS0004 // Certificate Validation has been disabled
            if (_connectionConfig.UseHTTPS)
            {
                ServicePointManager.ServerCertificateValidationCallback += (obj, cert, chain, errors) =>
                {
                    // ignore all cert errors when validating URL response
                    return(true);
                };
            }
#pragma warning restore SCS0004 // Certificate Validation has been disabled


            if (_connectionConfig.Authentication == "default")
            {
                // use windows authentication
                _client = new HttpClient(new HttpClientHandler()
                {
                    UseDefaultCredentials = true
                });
            }
            else
            {
                //alternative auth
                _client = new HttpClient();
            }

            _client.DefaultRequestHeaders.Add("User-Agent", "Certify/App");
            _client.Timeout = new TimeSpan(0, 20, 0); // 20 min timeout on service api calls
        }
Example #3
0
        public CertifyApiClient(Providers.IServiceConfigProvider configProvider, Shared.ServerConnection config = null)
        {
            _configProvider   = configProvider;
            _connectionConfig = config ?? GetDefaultServerConnection();

            _baseUri = $"{(_connectionConfig.UseHTTPS ? "https" : "http")}://{_connectionConfig.Host}:{_connectionConfig.Port}" + _baseUri;

            CreateHttpClient();
        }
Example #4
0
 public CertifyServiceClient(Providers.IServiceConfigProvider configProvider, Shared.ServerConnection config = null) : base(configProvider, config)
 {
     _statusHubUri = $"{(_connectionConfig.UseHTTPS ? "https" : "http")}://{_connectionConfig.Host}:{_connectionConfig.Port}" + _statusHubUri;
 }