public JwtTokenService(SecurityTokenHandler tokenHandler, SecurityTokenDescriptor tokenDescriptor, IOptions <AppSettingsOptions> appSettings, IOptions <JwtConfigOptions> jwtConfig)
 {
     _tokenHandler    = tokenHandler;
     _tokenDescriptor = tokenDescriptor;
     _appSettings     = appSettings.Value;
     _jwtConfig       = jwtConfig.Value;
 }
 public AccountController(UserManager <User> userManager, ShopDbContext context, ITokenService tokenService, IOptions <AppSettingsOptions> appSettings, IAuthService authService, IMfaService mfaService)
 {
     _userManager  = userManager;
     _context      = context;
     _tokenService = tokenService;
     _appSettings  = appSettings.Value;
     _authService  = authService;
     _mfaService   = mfaService;
 }
예제 #3
0
        public Startup(ILoggerFactory loggerFactory, IHostingEnvironment env)
        {
            Configuration = new ConfigurationBuilder()
                            .SetBasePath(env.ContentRootPath)
                            .AddJsonFile("appsettings.json")
                            .Build();

            Environment = env;
            _settings   = Configuration.GetSection("AppSettings").Get <AppSettingsOptions>();
        }
예제 #4
0
 public AppSettingsManager()
 {
     foreach (var prop in typeof(T).GetProperties())
     {
         var attr = prop.GetCustomAttribute <AppSettingsAttribute>();
         if (attr != null)
         {
             AppSettingsKeys.Add(attr.Key, prop);
             AppSettingsOptions.Add(attr.Key, attr);
         }
     }
     Load();
 }
        public AppSettingsOptions GetAppSettings()
        {
            var appSettings = new AppSettingsOptions()
            {
                MyConnectionString  = _appSettings.Value.MyConnectionString,
                ConnectionString    = _appSettings.Value.ConnectionString,
                EnvironmentName     = _appSettings.Value.EnvironmentName,
                EnvironmentSlotName = _appSettings.Value.EnvironmentSlotName
            };

            return(appSettings);
            //return Ok(appSettings);
        }
예제 #6
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            if (_environment.IsDevelopment())
            {
                services.ConfigureWritable <AppSettingsOptions>(Configuration.GetSection(AppSettingsOptions.AppSettings), "appsettings.Development.json");
                services.ConfigureWritable <MailerSettingsOptions>(Configuration.GetSection(MailerSettingsOptions.MailerSettings), "appsettings.Development.json");
            }
            else
            {
                services.ConfigureWritable <AppSettingsOptions>(Configuration.GetSection(AppSettingsOptions.AppSettings), "appsettings.json");
                services.ConfigureWritable <MailerSettingsOptions>(Configuration.GetSection(MailerSettingsOptions.MailerSettings), "appsettings.json");
            }



            services.AddDbContext <AppDbContext>((serviceProvider, builder) =>
            {
                AppSettingsOptions appSettingsOptions = Configuration.GetSection(AppSettingsOptions.AppSettings).Get <AppSettingsOptions>();

                builder.UseMySql(appSettingsOptions.ConnectionString);
            });

            services.AddDefaultIdentity <ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = false)
            .AddEntityFrameworkStores <AppDbContext>();
            services.AddRazorPages()
            .WithRazorPagesRoot("/Portfolio/Pages")
            .AddRazorPagesOptions(options =>
            {
                options.Conventions.AuthorizeAreaFolder("Admin", "/");
            }
                                  ).AddRazorRuntimeCompilation();

            services.ConfigureApplicationCookie(options =>
            {
                options.LoginPath        = $"/Identity/Account/Login";
                options.LogoutPath       = $"/Identity/Account/Logout";
                options.AccessDeniedPath = $"/Identity/Account/AccessDenied";
            });

            services.AddTransient <IEmailSender, EmailSender>();

            services.AddTransient <SimplePageService>();
            services.AddTransient <PortfolioNavigationService>();
            services.AddTransient <SetupService>();
            services.AddTransient <MyProjectService>();
        }
예제 #7
0
        /// <summary>
        /// 构造函数
        /// </summary>
        static SpecificationDocumentBuilder()
        {
            // 载入配置
            _specificationDocumentSettings = App.GetConfig <SpecificationDocumentSettingsOptions>("SpecificationDocumentSettings", true);
            _appSettings = App.Settings;

            // 初始化常量
            _groupOrderRegex          = new Regex(@"@(?<order>[0-9]+$)");
            GetActionGroupsCached     = new ConcurrentDictionary <MethodInfo, IEnumerable <GroupExtraInfo> >();
            GetControllerGroupsCached = new ConcurrentDictionary <Type, IEnumerable <GroupExtraInfo> >();
            GetGroupOpenApiInfoCached = new ConcurrentDictionary <string, SpecificationOpenApiInfo>();
            GetControllerTagCached    = new ConcurrentDictionary <ControllerActionDescriptor, string>();
            GetActionTagCached        = new ConcurrentDictionary <ApiDescription, string>();

            // 默认分组,支持多个逗号分割
            DocumentGroupExtras = new List <GroupExtraInfo> {
                ResolveGroupExtraInfo(_specificationDocumentSettings.DefaultGroupName)
            };

            // 加载所有分组
            DocumentGroups = ReadGroups();
        }
예제 #8
0
 public JWTFactory(AppSettingsOptions appSettings)
 {
     _appSettings = appSettings;
 }
예제 #9
0
 public InaccessibleAssignmentsModel(ILogger <InaccessibleAssignmentsModel> logger, IOptions <AppSettingsOptions> options)
 {
     _logger  = logger;
     _options = options.Value;
 }
예제 #10
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var appSettingsOptions = new AppSettingsOptions();

            Configuration.GetSection(AppSettingsOptions.AppSettings).Bind(appSettingsOptions);

            //DI Configuration appsettings for later use
            services.AddSingleton <AppSettingsOptions>(appSettingsOptions);
            //DI JWT Factory use for creating
            services.AddScoped <JWTFactory>();

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "MCQ API", Version = "v1"
                });
                c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
                {
                    Description = "JWT Authorization header using the bearer scheme",
                    Name        = "Authorization",
                    In          = ParameterLocation.Header,
                    Type        = SecuritySchemeType.ApiKey
                });

                c.AddSecurityRequirement(new OpenApiSecurityRequirement
                {
                    {
                        new OpenApiSecurityScheme
                        {
                            Reference = new OpenApiReference
                            {
                                Id   = "Bearer",
                                Type = ReferenceType.SecurityScheme
                            }
                        },
                        new List <string>()
                    }
                });
            });

            // Cors configure
            services.AddCors(opts =>
            {
                opts.AddPolicy("AllowAll", builder =>
                {
                    builder
                    // .AllowAnyOrigin()
                    .AllowAnyMethod()
                    .AllowAnyHeader()
                    .AllowCredentials();
                });
            });

            // Add jwt authentication
            services.AddAuthentication(x =>
            {
                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(cfg =>
            {
                cfg.RequireHttpsMetadata = false;
                cfg.SaveToken            = true;

                cfg.TokenValidationParameters = new TokenValidationParameters()
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         =
                        new SymmetricSecurityKey(Encoding.UTF8.GetBytes(appSettingsOptions.JwtSecret)),
                    ValidateIssuer        = true,
                    ValidIssuer           = appSettingsOptions.Issuer,
                    ValidateAudience      = true,
                    ValidAudience         = appSettingsOptions.Audience,
                    RequireExpirationTime = false
                };
            });


            // DB configure
            services.AddDbContext <DBContext>(opts =>
                                              opts
                                              .UseNpgsql(Configuration["ConnectionString:McqDB"])
                                              .UseLoggerFactory(LoggerFactory.Create(builder => builder.AddConsole()))
                                              );
            services.AddScoped <DBContext>();

            // Add unit of work scope
            services.AddScoped <IUnitOfWork, UnitOfWork>();

            // set up redis cache
            var redisCacheSettings = new RedisSettingsOptions();

            Configuration.GetSection(RedisSettingsOptions.RedisSettings).Bind(redisCacheSettings);
            services.AddSingleton(redisCacheSettings);
            if (redisCacheSettings.Enabled)
            {
                services.AddStackExchangeRedisCache(options =>
                                                    options.Configuration = redisCacheSettings.ConnectionString);
                services.AddSingleton <CacheHelper>();
            }

            // Configure controller
            services.AddControllers().AddNewtonsoftJson(opt =>
                                                        opt.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore);

            // Auto mapper
            services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());

            // get config object
            AppConfig.SetConfig(Configuration);
            // Add services
            AddServicesScoped(services);

            // create singleton context accessor
            services.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddScoped <ClaimProvider>();

            // API versioning
            services.AddApiVersioning(x =>
            {
                x.DefaultApiVersion = new ApiVersion(1, 0);
                x.AssumeDefaultVersionWhenUnspecified = true;
                x.ReportApiVersions = true;
            });

            ////  in case of SignalR
            // services.AddSignalR();
            // services.AddSingleton<IHubConnectionManager, HubConnectionManager>();
            // services.AddSingleton<IHubNotificationHelper, HubNotificationHelper>();
        }
예제 #11
0
 public SettingsController(IOptions <AppSettingsOptions> options)
 {
     _options = options.Value;
 }