Пример #1
0
 public OneStopUtils(IConfiguration Configuration, ILogger logger)
 {
     this.Configuration = Configuration;
     _dynamics          = OneStopUtils.SetupDynamics(Configuration);
     _onestopRestClient = OneStopUtils.SetupOneStopClient(Configuration, logger);
     _logger            = logger;
 }
 public LdbExport(IConfiguration Configuration)
 {
     this.Configuration = Configuration;
     this._dynamics     = OneStopUtils.SetupDynamics(Configuration);
 }
Пример #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            IDynamicsClient dynamicsClient = OneStopUtils.SetupDynamics(Configuration);

            services.AddSingleton <IReceiveFromHubService>(new ReceiveFromHubService(dynamicsClient, _loggerFactory.CreateLogger("IReceiveFromHubService"), Configuration));

            services.AddSingleton <ILogger>(_loggerFactory.CreateLogger("OneStopController"));

            services.AddMvc(config =>
            {
                if (!string.IsNullOrEmpty(Configuration["JWT_TOKEN_KEY"]))
                {
                    var policy = new AuthorizationPolicyBuilder()
                                 .RequireAuthenticatedUser()
                                 .Build();
                    config.Filters.Add(new AuthorizeFilter(policy));
                }
            });

            // Other ConfigureServices() code...

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "JAG LCRB One Stop Service", Version = "v1"
                });
            });

            services.AddIdentity <IdentityUser, IdentityRole>()
            .AddDefaultTokenProviders();

            if (!string.IsNullOrEmpty(Configuration["JWT_TOKEN_KEY"]))
            {
                // Configure JWT authentication
                services.AddAuthentication(o =>
                {
                    o.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                    o.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
                }).AddJwtBearer(o =>
                {
                    o.SaveToken                 = true;
                    o.RequireHttpsMetadata      = false;
                    o.TokenValidationParameters = new TokenValidationParameters()
                    {
                        RequireExpirationTime = false,
                        ValidIssuer           = Configuration["JWT_VALID_ISSUER"],
                        ValidAudience         = Configuration["JWT_VALID_AUDIENCE"],
                        IssuerSigningKey      = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["JWT_TOKEN_KEY"]))
                    };
                });
            }

            services.AddHangfire(config =>
            {
                // Change this line if you wish to have Hangfire use persistent storage.
                config.UseMemoryStorage();
                // enable console logs for jobs
                config.UseConsole();
            });

            // health checks.
            services.AddHealthChecks(checks =>
            {
                checks.AddValueTaskCheck("HTTP Endpoint", () => new
                                         ValueTask <IHealthCheckResult>(HealthCheckResult.Healthy("Ok")));
            });
        }