private static void ConfigAuthorizaion(IServiceCollection services, Hcs.Platform.PlatformBuilder builder)
 {
     services.AddAuthorization(options =>
     {
         options.AddPolicy(Const.Policy.ContollerMethod, policy => policy.Requirements.Add(new ControllerMethodRequirement()));
     });
 }
        public static IMvcBuilder AddHcsPlatform(this IServiceCollection services, Action <Hcs.Platform.PlatformBuilder> config)
        {
            var mvcBuilder = services.AddMvc();

            mvcBuilder.AddJsonOptions(options => options.SerializerSettings.ContractResolver      = new Newtonsoft.Json.Serialization.DefaultContractResolver());
            mvcBuilder.AddJsonOptions(options => options.SerializerSettings.DateTimeZoneHandling  = Newtonsoft.Json.DateTimeZoneHandling.Utc);
            mvcBuilder.AddJsonOptions(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);
            mvcBuilder.ConfigureApplicationPartManager(p => p.FeatureProviders.Add(new Hcs.Platform.Core.ApplicationFeatureProvider.ControllerFeatureProvider()));

            ConfigServices(services);
            //modules
            var builder = new Hcs.Platform.PlatformBuilder(mvcBuilder.Services);

            DefaultPlatformConfig.DefaultConfig(builder);
            config(builder);
            ConfigBuilderConfigService(services, builder);
            return(mvcBuilder);
        }
        private static void ConfigAuthentication(IServiceCollection services, Hcs.Platform.PlatformBuilder builder)
        {
            var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.JwtConfigBuilder.IssuerSigningKey));

            builder.JwtConfigBuilder.SigningCredentials = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options =>
            {
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer           = true,
                    ValidateAudience         = true,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,
                    ValidIssuer       = builder.JwtConfigBuilder.Issuer,
                    ValidAudience     = builder.JwtConfigBuilder.Audience,
                    LifetimeValidator = ValidateTokenLifeTime,
                    IssuerSigningKey  = key
                };
            });
        }
Beispiel #4
0
 public static PlatformBuilder AddModule <TModule>(this PlatformBuilder builder) where TModule : class, IPlatformModule, new()
 {
     return(builder.AddModule(new TModule()));
 }
Beispiel #5
0
 public static PlatformBuilder UseLocalFileStroage(this PlatformBuilder builder, string rootPath)
 {
     builder.Services.AddSingleton <File.IFileStorage>(c => new Core.File.LocalDisk.LocalDiskFileStorage(rootPath));
     return(builder);
 }
Beispiel #6
0
 public static PlatformBuilder UseAzureBlobStorage(this PlatformBuilder builder, string storageAccountName, string accessKey, string containerName)
 {
     builder.Services.AddSingleton <File.IFileStorage>(c => new Core.File.AzureBlob.AzureBlobStorage(storageAccountName, accessKey, containerName));
     return(builder);
 }