Ejemplo n.º 1
0
 public WechatController(LogInManager logInManager,
                         ITenantCache tenantCache,
                         AbpLoginResultTypeHelper abpLoginResultTypeHelper,
                         TokenAuthConfiguration configuration,
                         UserManager userManager,
                         ICacheManager cacheManager,
                         IOptions <JwtBearerOptions> jwtOptions,
                         IExternalAuthManager externalAuthManager,
                         IOptions <IdentityOptions> identityOptions,
                         IWechatService wechatService,
                         SignInManager signInManager)
     : base(logInManager, tenantCache, abpLoginResultTypeHelper, configuration, userManager, cacheManager, jwtOptions, externalAuthManager, identityOptions)
 {
     _wechatService     = wechatService;
     _signInManager     = signInManager;
     RecaptchaValidator = NullRecaptchaValidator.Instance;
 }
Ejemplo n.º 2
0
 public TokenAuthController(
     LogInManager logInManager,
     ITenantCache tenantCache,
     StudioXLoginResultTypeHelper studioXLoginResultTypeHelper,
     TokenAuthConfiguration configuration,
     IExternalAuthConfiguration externalAuthConfiguration,
     IExternalAuthManager externalAuthManager,
     UserRegistrationManager userRegistrationManager)
 {
     this.logInManager = logInManager;
     this.tenantCache  = tenantCache;
     this.studioXLoginResultTypeHelper = studioXLoginResultTypeHelper;
     this.configuration             = configuration;
     this.externalAuthConfiguration = externalAuthConfiguration;
     this.externalAuthManager       = externalAuthManager;
     this.userRegistrationManager   = userRegistrationManager;
 }
Ejemplo n.º 3
0
 public TokenAuthController(
     LogInManager logInManager,
     AbpLoginResultTypeHelper abpLoginResultTypeHelper,
     TokenAuthConfiguration configuration,
     UserManager userManager,
     ICacheManager cacheManager,
     IOptions <IdentityOptions> identityOptions,
     ITenantCache tenantCache)
 {
     _tenantCache = tenantCache;
     _abpLoginResultTypeHelper = abpLoginResultTypeHelper;
     _configuration            = configuration;
     _logInManager             = logInManager;
     _userManager     = userManager;
     _cacheManager    = cacheManager;
     _identityOptions = identityOptions.Value;
 }
 public TokenAuthController(
     LogInManager logInManager,
     ITenantCache tenantCache,
     AbpLoginResultTypeHelper abpLoginResultTypeHelper,
     TokenAuthConfiguration configuration,
     IExternalAuthConfiguration externalAuthConfiguration,
     IExternalAuthManager externalAuthManager,
     UserRegistrationManager userRegistrationManager)
 {
     _logInManager              = logInManager;
     _tenantCache               = tenantCache;
     _abpLoginResultTypeHelper  = abpLoginResultTypeHelper;
     _configuration             = configuration;
     _externalAuthConfiguration = externalAuthConfiguration;
     _externalAuthManager       = externalAuthManager;
     _userRegistrationManager   = userRegistrationManager;
 }
 public TokenAuthController(
     LogInManager logInManager,
     ITenantCache tenantCache,
     AbpLoginResultTypeHelper abpLoginResultTypeHelper,
     TokenAuthConfiguration configuration,
     UserManager userManager,
     ICacheManager cacheManager,
     IOptions <JwtBearerOptions> jwtOptions,
     IExternalAuthConfiguration externalAuthConfiguration,
     IExternalAuthManager externalAuthManager,
     UserRegistrationManager userRegistrationManager,
     IImpersonationManager impersonationManager,
     IUserLinkManager userLinkManager,
     IAppNotifier appNotifier,
     ISmsSender smsSender,
     IEmailSender emailSender,
     IOptions <IdentityOptions> identityOptions,
     GoogleAuthenticatorProvider googleAuthenticatorProvider,
     ExternalLoginInfoManagerFactory externalLoginInfoManagerFactory,
     ISettingManager settingManager,
     IJwtSecurityStampHandler securityStampHandler,
     AbpUserClaimsPrincipalFactory <User, Role> claimsPrincipalFactory)
 {
     _logInManager             = logInManager;
     _tenantCache              = tenantCache;
     _abpLoginResultTypeHelper = abpLoginResultTypeHelper;
     _configuration            = configuration;
     _userManager              = userManager;
     _cacheManager             = cacheManager;
     _jwtOptions = jwtOptions;
     _externalAuthConfiguration = externalAuthConfiguration;
     _externalAuthManager       = externalAuthManager;
     _userRegistrationManager   = userRegistrationManager;
     _impersonationManager      = impersonationManager;
     _userLinkManager           = userLinkManager;
     _appNotifier = appNotifier;
     _smsSender   = smsSender;
     _emailSender = emailSender;
     _googleAuthenticatorProvider     = googleAuthenticatorProvider;
     _externalLoginInfoManagerFactory = externalLoginInfoManagerFactory;
     _settingManager         = settingManager;
     _securityStampHandler   = securityStampHandler;
     _identityOptions        = identityOptions.Value;
     _claimsPrincipalFactory = claimsPrincipalFactory;
     RecaptchaValidator      = NullRecaptchaValidator.Instance;
 }
 public UploadController(
     LogInManager logInManager,
     ITenantCache tenantCache,
     AbpLoginResultTypeHelper abpLoginResultTypeHelper,
     TokenAuthConfiguration configuration,
     IExternalAuthConfiguration externalAuthConfiguration,
     IExternalAuthManager externalAuthManager,
     UserRegistrationManager userRegistrationManager, IHostingEnvironment env)
 {
     _logInManager              = logInManager;
     _tenantCache               = tenantCache;
     _abpLoginResultTypeHelper  = abpLoginResultTypeHelper;
     _configuration             = configuration;
     _externalAuthConfiguration = externalAuthConfiguration;
     _externalAuthManager       = externalAuthManager;
     _userRegistrationManager   = userRegistrationManager;
     _appConfiguration          = env.GetAppConfiguration();
 }
Ejemplo n.º 7
0
 public TokenAuthController(
     LogInManager logInManager,
     ITenantCache tenantCache,
     AbpLoginResultTypeHelper abpLoginResultTypeHelper,
     TokenAuthConfiguration configuration,
     UserManager userManager,
     ICacheManager cacheManager,
     IOptions <JwtBearerOptions> jwtOptions,
     IExternalAuthConfiguration externalAuthConfiguration,
     IExternalAuthManager externalAuthManager,
     UserRegistrationManager userRegistrationManager,
     IImpersonationManager impersonationManager,
     IUserLinkManager userLinkManager,
     IAppNotifier appNotifier,
     ISmsSender smsSender,
     IEmailSender emailSender,
     IOptions <IdentityOptions> identityOptions,
     GoogleAuthenticatorProvider googleAuthenticatorProvider,
     IRepository <PERSONALS, string> personalsRepo,
     IRepository <PERSONALS_MEMBER, string> personalsMemberRepo,
     IRepository <MP_UserPersonals> mpUserPersonalsRepo
     )
 {
     _logInManager             = logInManager;
     _tenantCache              = tenantCache;
     _abpLoginResultTypeHelper = abpLoginResultTypeHelper;
     _configuration            = configuration;
     _userManager              = userManager;
     _cacheManager             = cacheManager;
     _jwtOptions = jwtOptions;
     _externalAuthConfiguration = externalAuthConfiguration;
     _externalAuthManager       = externalAuthManager;
     _userRegistrationManager   = userRegistrationManager;
     _impersonationManager      = impersonationManager;
     _userLinkManager           = userLinkManager;
     _appNotifier = appNotifier;
     _smsSender   = smsSender;
     _emailSender = emailSender;
     _googleAuthenticatorProvider = googleAuthenticatorProvider;
     _identityOptions             = identityOptions.Value;
     _personalsRepo       = personalsRepo;
     _personalsMemberRepo = personalsMemberRepo;
     _mpUserPersonalsRepo = mpUserPersonalsRepo;
 }
 public TokenAuthController(
     LogInManager logInManager,
     ITenantCache tenantCache,
     AbpLoginResultTypeHelper abpLoginResultTypeHelper,
     TokenAuthConfiguration configuration,
     IUserManager userManager,
     ICacheManager cacheManager,
     IOptions <JwtBearerOptions> jwtOptions,
     IExternalAuthConfiguration externalAuthConfiguration,
     IExternalAuthManager externalAuthManager,
     UserRegistrationManager userRegistrationManager,
     IImpersonationManager impersonationManager,
     IUserLinkManager userLinkManager,
     IAppNotifier appNotifier,
     ISmsSender smsSender,
     IEmailSender emailSender,
     IOptions <IdentityOptions> identityOptions,
     GoogleAuthenticatorProvider googleAuthenticatorProvider,
     IRepository <Tenant> tenantRepository,
     IAccountAppService accountAppService,
     IRepository <User, long> userRepository)
 {
     _logInManager             = logInManager;
     _tenantCache              = tenantCache;
     _abpLoginResultTypeHelper = abpLoginResultTypeHelper;
     _configuration            = configuration;
     _userManager              = userManager;
     _cacheManager             = cacheManager;
     _jwtOptions = jwtOptions;
     _externalAuthConfiguration = externalAuthConfiguration;
     _externalAuthManager       = externalAuthManager;
     _userRegistrationManager   = userRegistrationManager;
     _impersonationManager      = impersonationManager;
     _userLinkManager           = userLinkManager;
     _appNotifier = appNotifier;
     _smsSender   = smsSender;
     _emailSender = emailSender;
     _googleAuthenticatorProvider = googleAuthenticatorProvider;
     _identityOptions             = identityOptions.Value;
     _tenantRepository            = tenantRepository;
     _accountAppService           = accountAppService;
     _userRepository = userRepository;
 }
Ejemplo n.º 9
0
 public TokenAuthController(
     LogInManager logInManager,
     ITenantCache tenantCache,
     AbpLoginResultTypeHelper abpLoginResultTypeHelper,
     TokenAuthConfiguration configuration,
     //IExternalAuthConfiguration externalAuthConfiguration,
     //IExternalAuthManager externalAuthManager
     //UserRegistrationManager userRegistrationManager
     IRepository <User, long> userRepository)
 {
     _logInManager             = logInManager;
     _tenantCache              = tenantCache;
     _abpLoginResultTypeHelper = abpLoginResultTypeHelper;
     _configuration            = configuration;
     //_externalAuthConfiguration = externalAuthConfiguration;
     //_externalAuthManager = externalAuthManager;
     //_userRegistrationManager = userRegistrationManager;
     _userRepository = userRepository;
 }
Ejemplo n.º 10
0
 public ResourceOwnerPasswordValidator(
     IConfiguration appConfiguration,
     LogInManager logInManager,
     ITenantCache tenantCache,
     AbpLoginResultTypeHelper abpLoginResultTypeHelper,
     TokenAuthConfiguration configuration,
     IExternalAuthConfiguration externalAuthConfiguration,
     IExternalAuthManager externalAuthManager,
     UserRegistrationManager userRegistrationManager)
 {
     _appConfiguration          = appConfiguration;
     _logInManager              = logInManager;
     _tenantCache               = tenantCache;
     _abpLoginResultTypeHelper  = abpLoginResultTypeHelper;
     _configuration             = configuration;
     _externalAuthConfiguration = externalAuthConfiguration;
     _externalAuthManager       = externalAuthManager;
     _userRegistrationManager   = userRegistrationManager;
 }
Ejemplo n.º 11
0
 public TokenAuthController(
     LogInManager logInManager,
     ITenantCache tenantCache,
     TokenAuthConfiguration configuration,
     IImpersonationManager impersonationManager,
     IUserLinkManager userLinkManager,
     IOptions <IdentityOptions> identityOptions,
     IRepository <User, long> userRepository,
     IPasswordHasher <User> passwordHasher)
 {
     _logInManager         = logInManager;
     _tenantCache          = tenantCache;
     _configuration        = configuration;
     _impersonationManager = impersonationManager;
     _userLinkManager      = userLinkManager;
     _userRepository       = userRepository;
     _passwordHasher       = passwordHasher;
     _identityOptions      = identityOptions.Value;
 }
Ejemplo n.º 12
0
 public TokenAuthController(
     LogInManager logInManager,
     ITenantCache tenantCache,
     AbpLoginResultTypeHelper abpLoginResultTypeHelper,
     TokenAuthConfiguration configuration,
     IExternalAuthConfiguration externalAuthConfiguration,
     IExternalAuthManager externalAuthManager,
     UserRegistrationManager userRegistrationManager,
     IOptions <AppSettings> appSettings)
 {
     _logInManager              = logInManager;
     _tenantCache               = tenantCache;
     _abpLoginResultTypeHelper  = abpLoginResultTypeHelper;
     _configuration             = configuration;
     _externalAuthConfiguration = externalAuthConfiguration;
     _externalAuthManager       = externalAuthManager;
     _userRegistrationManager   = userRegistrationManager;
     _appSettings               = appSettings;
     uploadHelper               = new UploadHelper(appSettings);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="logInManager"></param>
 /// <param name="tenantCache"></param>
 /// <param name="abpLoginResultTypeHelper"></param>
 /// <param name="configuration"></param>
 /// <param name="externalAuthConfiguration"></param>
 /// <param name="externalAuthManager"></param>
 /// <param name="userRegistrationManager"></param>
 /// <param name="customerAppService"></param>
 /// <param name="hostingEnv"></param>
 public TokenAuthController(
     LogInManager logInManager,
     ITenantCache tenantCache,
     AbpLoginResultTypeHelper abpLoginResultTypeHelper,
     TokenAuthConfiguration configuration,
     IExternalAuthConfiguration externalAuthConfiguration,
     IExternalAuthManager externalAuthManager,
     UserRegistrationManager userRegistrationManager,
     ICustomerAppService customerAppService, IHostingEnvironment hostingEnv)
 {
     _logInManager              = logInManager;
     _tenantCache               = tenantCache;
     _abpLoginResultTypeHelper  = abpLoginResultTypeHelper;
     _configuration             = configuration;
     _externalAuthConfiguration = externalAuthConfiguration;
     _externalAuthManager       = externalAuthManager;
     _userRegistrationManager   = userRegistrationManager;
     _customerAppService        = customerAppService;
     this._hostingEnv           = hostingEnv;
 }
Ejemplo n.º 14
0
 public AuthorizeControllerBase(
     LogInManager logInManager,
     ITenantCache tenantCache,
     AbpLoginResultTypeHelper abpLoginResultTypeHelper,
     TokenAuthConfiguration configuration,
     UserManager userManager,
     ICacheManager cacheManager,
     IOptions <JwtBearerOptions> jwtOptions,
     IExternalAuthManager externalAuthManager,
     IOptions <IdentityOptions> identityOptions)
 {
     LogInManager             = logInManager;
     TenantCache              = tenantCache;
     AbpLoginResultTypeHelper = abpLoginResultTypeHelper;
     Configuration            = configuration;
     UserManager              = userManager;
     CacheManager             = cacheManager;
     JwtOptions          = jwtOptions;
     ExternalAuthManager = externalAuthManager;
     IdentityOptions     = identityOptions.Value;
 }
Ejemplo n.º 15
0
 public TokenAuthController(
     LogInManager logInManager,
     ITenantCache tenantCache,
     ShaLoginResultTypeHelper ShaLoginResultTypeHelper,
     TokenAuthConfiguration configuration,
     IExternalAuthConfiguration externalAuthConfiguration,
     IExternalAuthManager externalAuthManager,
     UserRegistrationManager userRegistrationManager,
     IRepository <Person, Guid> personRepository,
     IRepository <MobileDevice, Guid> mobileDeviceRepository)
 {
     _logInManager              = logInManager;
     _tenantCache               = tenantCache;
     _shaLoginResultTypeHelper  = ShaLoginResultTypeHelper;
     _configuration             = configuration;
     _externalAuthConfiguration = externalAuthConfiguration;
     _externalAuthManager       = externalAuthManager;
     _userRegistrationManager   = userRegistrationManager;
     _personRepository          = personRepository;
     _mobileDeviceRepository    = mobileDeviceRepository;
 }
Ejemplo n.º 16
0
 public TokenAuthController(
     LogInManager logInManager,
     ITenantCache tenantCache,
     AbpLoginResultTypeHelper abpLoginResultTypeHelper,
     TokenAuthConfiguration configuration,
     IExternalAuthConfiguration externalAuthConfiguration,
     IExternalAuthManager externalAuthManager,
     UserRegistrationManager userRegistrationManager,
     IDapperRepository <AbpUsersEx, long> userRepository,
     RoleNameAppService roleNameAppService)
 {
     _logInManager              = logInManager;
     _tenantCache               = tenantCache;
     _abpLoginResultTypeHelper  = abpLoginResultTypeHelper;
     _configuration             = configuration;
     _externalAuthConfiguration = externalAuthConfiguration;
     _externalAuthManager       = externalAuthManager;
     _userRegistrationManager   = userRegistrationManager;
     _userRepository            = userRepository;
     _roleNameAppService        = roleNameAppService;
 }
Ejemplo n.º 17
0
 public TokenAuthController(
     LogInManager logInManager,
     ITenantCache tenantCache,
     AbpLoginResultTypeHelper abpLoginResultTypeHelper,
     TokenAuthConfiguration configuration,
     UserManager userManager,
     ICacheManager cacheManager,
     IOptions <JwtBearerOptions> jwtOptions,
     IExternalAuthConfiguration externalAuthConfiguration,
     IExternalAuthManager externalAuthManager,
     UserRegistrationManager userRegistrationManager,
     IImpersonationManager impersonationManager,
     IUserLinkManager userLinkManager,
     IAppNotifier appNotifier,
     ISmsSender smsSender,
     IEmailSender emailSender,
     IOptions <IdentityOptions> identityOptions,
     GoogleAuthenticatorProvider googleAuthenticatorProvider,
     IdentityServerTokenGeneratorFacade identityServerTokenGeneratorFacade)
 {
     _logInManager             = logInManager;
     _tenantCache              = tenantCache;
     _abpLoginResultTypeHelper = abpLoginResultTypeHelper;
     _configuration            = configuration;
     _userManager              = userManager;
     _cacheManager             = cacheManager;
     _jwtOptions = jwtOptions;
     _externalAuthConfiguration = externalAuthConfiguration;
     _externalAuthManager       = externalAuthManager;
     _userRegistrationManager   = userRegistrationManager;
     _impersonationManager      = impersonationManager;
     _userLinkManager           = userLinkManager;
     _appNotifier = appNotifier;
     _smsSender   = smsSender;
     _emailSender = emailSender;
     _googleAuthenticatorProvider        = googleAuthenticatorProvider;
     _identityOptions                    = identityOptions.Value;
     _identityServerTokenGeneratorFacade = identityServerTokenGeneratorFacade;
 }
 public TokenAuthController(
     LogInManager logInManager,
     ITenantCache tenantCache,
     AbpLoginResultTypeHelper abpLoginResultTypeHelper,
     TokenAuthConfiguration configuration,
     IExternalAuthConfiguration externalAuthConfiguration,
     IExternalAuthManager externalAuthManager,
     IRepository <ApplicationUser, Guid> applicationUserReposatory,
     UserManager userManager,
     IEncryptionDecryptionService encryptionDecryptionService,
     UserRegistrationManager userRegistrationManager)
 {
     _logInManager                = logInManager;
     _tenantCache                 = tenantCache;
     _abpLoginResultTypeHelper    = abpLoginResultTypeHelper;
     _configuration               = configuration;
     _externalAuthConfiguration   = externalAuthConfiguration;
     _externalAuthManager         = externalAuthManager;
     _userRegistrationManager     = userRegistrationManager;
     _applicationUserReposatory   = applicationUserReposatory;
     _userManager                 = userManager;
     _encryptionDecryptionService = encryptionDecryptionService;
 }
 public PodAuthenticationController(
     IAccessTokenManager accessTokenManager,
     TokenAuthConfiguration tokenAuthConfiguration,
     AbpLoginResultTypeHelper abpLoginResultTypeHelper,
     LogInManager logInManager,
     IRepository <ExternalToken> externalTokensRepo,
     UserManager userManager,
     IRepository <User, long> userRepo,
     IRepository <StaticUser> staticUserRepo,
     IPodClient service,
     IJwtCreator jwtCreator)
 {
     this.accessTokenManager       = accessTokenManager;
     this.tokenAuthConfiguration   = tokenAuthConfiguration;
     this.abpLoginResultTypeHelper = abpLoginResultTypeHelper;
     this.logInManager             = logInManager;
     this.externalTokensRepo       = externalTokensRepo;
     this.userManager    = userManager;
     this.userRepo       = userRepo;
     this.staticUserRepo = staticUserRepo;
     _service            = service;
     _jwtCreator         = jwtCreator;
 }
 public TokenAuthController(
     LogInManager logInManager,
     ITenantCache tenantCache,
     AbpLoginResultTypeHelper abpLoginResultTypeHelper,
     TokenAuthConfiguration configuration,
     IExternalAuthConfiguration externalAuthConfiguration,
     IExternalAuthManager externalAuthManager,
     UserRegistrationManager userRegistrationManager,
     UserManager userManager,
     TenantManager tenantManager,
     ICryptoService cryptoService)
 {
     _logInManager              = logInManager;
     _tenantCache               = tenantCache;
     _abpLoginResultTypeHelper  = abpLoginResultTypeHelper;
     _configuration             = configuration;
     _externalAuthConfiguration = externalAuthConfiguration;
     _externalAuthManager       = externalAuthManager;
     _userRegistrationManager   = userRegistrationManager;
     _userManager               = userManager;
     _tenantManager             = tenantManager;
     _tokenHelper               = new TokenHelper(cryptoService);
 }
Ejemplo n.º 21
0
 public TokenAuthController(
     LogInManager logInManager,
     ITenantCache tenantCache,
     AbpLoginResultTypeHelper abpLoginResultTypeHelper,
     TokenAuthConfiguration configuration,
     IExternalAuthConfiguration externalAuthConfiguration,
     IExternalAuthManager externalAuthManager,
     UserRegistrationManager userRegistrationManager,
     AbpUserClaimsPrincipalFactory <User, Role> claimsPrincipalFactory,
     IRepository <User, long> userRepository,
     IRepository <Tenant> tenantRepository)
 {
     _logInManager              = logInManager;
     _tenantCache               = tenantCache;
     _abpLoginResultTypeHelper  = abpLoginResultTypeHelper;
     _configuration             = configuration;
     _externalAuthConfiguration = externalAuthConfiguration;
     _externalAuthManager       = externalAuthManager;
     _userRegistrationManager   = userRegistrationManager;
     _claimsPrincipalFactory    = claimsPrincipalFactory;
     _userRepository            = userRepository;
     _tenantRepository          = tenantRepository;
 }
Ejemplo n.º 22
0
 public TokenController(IUserService userService, TokenAuthConfiguration configuration)
 {
     _userService   = userService;
     _configuration = configuration;
 }
Ejemplo n.º 23
0
 public TokenAuthController(LoginManager loginManager, LoginResultTypeHelper loginResultTypeHelper, TokenAuthConfiguration tokenAuthConfiguration, UserManager userManager)
 {
     _loginManager          = loginManager;
     _loginResultTypeHelper = loginResultTypeHelper;
     _configuration         = tokenAuthConfiguration;
     _userManager           = userManager;
 }
Ejemplo n.º 24
0
 public ESWISAuthController(TokenAuthConfiguration configuration)
 {
     _configuration = configuration;
 }
 public TokenAuthController(IAccountAppService accountAppService, TokenAuthConfiguration configuration)
 {
     _accountAppService = accountAppService;
     _configuration     = configuration;
 }
Ejemplo n.º 26
0
 public TokenAuthController(IFacadeLoginManager facadeLoginManager, TokenAuthConfiguration configuration)
 {
     _facadeLoginManager = facadeLoginManager;
     _configuration      = configuration;
 }
Ejemplo n.º 27
0
        public void ConfigureServices(IServiceCollection services)
        {
            //services.Configure<JwtSetting>(Configuration.GetSection("JwtSetting"));
            //services.AddScoped<IUserService, UserService>();
            //services.AddScoped<ITokenService, TokenService>();
            //services.AddControllers();
            //services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();

            services.AddHttpClient();
            //services.AddHttpClient<HTTPClientHelper>();
            services.AddHttpContextAccessor();
            services.AddScoped <IIdentityService, IdentityService>();
            services.AddSingleton(typeof(IRepository <,>), typeof(RepositoryImpl <,>));
            //services.AddScoped<IRepository<TEntity>, RepositoryImpl<TEntity>>();

            var tokenAuthConfig = new TokenAuthConfiguration();

            tokenAuthConfig.SecurityKey        = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(_appConfiguration["Authentication:JwtBearer:SecurityKey"]));
            tokenAuthConfig.Issuer             = _appConfiguration["Authentication:JwtBearer:Issuer"];
            tokenAuthConfig.Audience           = _appConfiguration["Authentication:JwtBearer:Audience"];
            tokenAuthConfig.SigningCredentials = new SigningCredentials(tokenAuthConfig.SecurityKey, SecurityAlgorithms.HmacSha256);
            tokenAuthConfig.Expiration         = TimeSpan.FromHours(8);


            // MVC
            services.AddMvc(
                options => {
                options.Filters.Add(new CorsAuthorizationFilterFactory(_defaultCorsPolicyName));
                options.Filters.Add(typeof(LogFilter));
                options.Filters.Add <ExceptionFilter>();
                options.Filters.Add(typeof(WebApiResultFilter));
                options.RespectBrowserAcceptHeader = true;
            }
                ).AddApplicationPart(System.Reflection.Assembly.Load(new System.Reflection.AssemblyName("DataStat.WebCore")))
            .AddApplicationPart(System.Reflection.Assembly.Load(new System.Reflection.AssemblyName("DataStat.FrameWork")));
            //services.Add(new ServiceDescriptor(typeof(WorldContext), new WorldContext(Configuration.GetConnectionString("DefaultConnection"))));

            //跨域访问控制
            services.AddCors(
                options => options.AddPolicy(
                    _defaultCorsPolicyName,
                    builder => builder
                    //.WithOrigins(
                    //     //App: CorsOrigins in appsettings.json can contain more than one address separated by comma.
                    //    _appConfiguration["App:CorsOrigins"]
                    //        .Split(",", StringSplitOptions.RemoveEmptyEntries)
                    //        .Select(o => o.RemovePostFix("/"))
                    //        .ToArray()
                    //)
                    .AllowAnyOrigin()
                    .AllowAnyMethod()
                    .AllowAnyHeader()
                    .AllowCredentials()
                    )
                );

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    //是否开启发行人认证和发行人
                    ValidateIssuer = true,
                    ValidIssuer    = _appConfiguration["Authentication:JwtBearer:Issuer"],

                    //是否开启订阅人认证和订阅人
                    ValidateAudience = true,
                    ValidAudience    = _appConfiguration["Authentication:JwtBearer:Audience"],

                    //是否开启密钥认证和key值
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(_appConfiguration["Authentication:JwtBearer:SecurityKey"])),

                    //是否开启时间认证
                    ValidateLifetime = true,
                    //是否该令牌必须带有过期时间
                    RequireExpirationTime = true,

                    //认证时间的偏移量
                    ClockSkew = TimeSpan.Zero
                };
            });

            //Swagger
            services.AddSwaggerGen(options =>
            {
                options.SwaggerDoc("综治平台-数据统计服务", new OpenApiInfo {
                    Title = "综治平台-数据统计服务 API", Version = "v1.0"
                });
                //options.DocInclusionPredicate((docName, description) =>
                //{
                //    var classInfo = ((Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor)description.ActionDescriptor);
                //    var attributes = classInfo.MethodInfo.CustomAttributes;
                //    if (attributes.Count(t => t.AttributeType == typeof(HiddenApiAttribute)) == 0)
                //    {
                //        if (new string[] { "CreateByBatch", "UpdateByBatch", "UpdateDeleteByBatch", "GetAll" }.Contains(classInfo.MethodInfo.Name))
                //        {
                //            return false;
                //        }
                //        return true;
                //    }
                //    else
                //    {
                //        return false;
                //    }
                //});

                // Define the BearerAuth scheme that's in use
                //options.OperationFilter<SwaggerHeader>();
                //var security = new Dictionary<string, IEnumerable<string>> { { "bearerAuth", new string[] { } }, };
                //options.AddSecurityRequirement(security);

                options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme()
                {
                    Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
                    Name        = "Authorization",
                    In          = ParameterLocation.Header,
                    Type        = SecuritySchemeType.ApiKey,
                    Scheme      = JwtBearerDefaults.AuthenticationScheme
                });
                //Json Token认证方式,此方式为全局添加
                options.AddSecurityRequirement(new OpenApiSecurityRequirement
                {
                    {
                        new OpenApiSecurityScheme
                        {
                            Reference = new OpenApiReference {
                                Type = ReferenceType.SecurityScheme,
                                Id   = JwtBearerDefaults.AuthenticationScheme
                            }
                        }, new List <string>()
                    }
                });

                //在接口类、方法标记属性 [HiddenApi],可以阻止【Swagger文档】生成
                //options.DocumentFilter<HiddenApiFilter>();
                //options.DocumentFilter<CustomDocumentFiliter>();
                // Assign scope requirements to operations based on AuthorizeAttribute
                //options.OperationFilter<SecurityRequirementsOperationFilter>();
                //获取项目指定路径下xml文件
                // 为 Swagger JSON and UI设置xml文档注释路径
                //var basePath = Path.GetDirectoryName(typeof(Program).Assembly.Location);//获取应用程序所在目录
                //var xmlPath = Path.Combine(basePath, "swagger.xml");
                options.IncludeXmlComments(Path.Combine(_webRootPath, "swagger.xml"));
            });
        }
Ejemplo n.º 28
0
 public AuthenticationController(IRepository <User> userRepository, TokenAuthConfiguration configuration)
 {
     _userRepository = userRepository;
     _configuration  = configuration;
 }
Ejemplo n.º 29
0
 public TokenAuthController(TokenAuthConfiguration configuration, IMediator mediator)
 {
     _configuration = configuration;
     _mediator      = mediator;
 }