/// <summary> /// Constructor with dependency injection to <see cref="JwtOptions" /> /// </summary> /// <param name="options">The options.</param> public JwtTokenService(IOptions <JwtOptions> options) { jwtOptions = options.Value; }
public CustomSignInService(IUserRepository userRepository, IOptions <JwtOptions> jwtOptions) { _userRepository = userRepository ?? throw new ArgumentNullException(nameof(userRepository)); _jwtOptions = jwtOptions.Value ?? throw new ArgumentNullException(nameof(jwtOptions)); }
public void InstallServices(IServiceCollection services, IConfiguration configuration) { var jwtSettings = new JwtOptions(); configuration.Bind(nameof(jwtSettings), jwtSettings); services.AddSingleton(jwtSettings); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddScoped <IIdentityService, IdentityService>(); services.AddAuthentication(x => { x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; x.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(x => { x.SaveToken = true; x.TokenValidationParameters = new TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(jwtSettings.Secret)), ValidateIssuer = false, ValidateAudience = false, RequireExpirationTime = false, ValidateLifetime = true }; }); services.AddSwaggerGen(x => { x.SwaggerDoc("v1", new OpenApiInfo { Title = "MarkedNote", Version = "v1" }); x.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { Description = "Please insert JWT with bearer into field", Name = "Authorization", In = ParameterLocation.Header, Type = SecuritySchemeType.ApiKey }); x.AddSecurityRequirement(new OpenApiSecurityRequirement { { new OpenApiSecurityScheme { Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" } }, new string[] { } } }); var security = new Dictionary <string, IEnumerable <string> > { { "Bearer", new string[0] } }; }); }
public ValuesController(IUserManagerService userService, JwtOptions op) { }
public TokenService(IConfiguration configuration) { _configuration = configuration; _jwtOptions = _configuration.GetSection("JwtOptions").Get <JwtOptions>(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSingleton <IAuthentication, Authentication>(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddScoped <IUserSupervisor, UserSupervisor>(); services.AddScoped <IUserRepository, UserRepository>(); services.AddTransient <TokenManagerMiddleWare>(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.ConfigureSwaggerGen(options => { options.IncludeXmlComments(Path.ChangeExtension(Assembly.GetEntryAssembly().Location, "xml")); //options.OperationFilter<AuthorizationHeaderParameterOperationFilter>(); }); services.AddDbContext <LocalDbContext>(options => options.UseInMemoryDatabase(databaseName: "JobsityChat")); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Version = "v1", Title = "CHAT", Description = "CHAT DEMO APP", TermsOfService = "None", Contact = new Contact { Name = "LeonardoSanchez", Email = "*****@*****.**", Url = "https://twitter.com/ingleo44" } }); }); var jwtSection = Configuration.GetSection("jwt"); var jwtOptions = new JwtOptions(); jwtSection.Bind(jwtOptions); services.Configure <JwtOptions>(jwtSection); services.ConfigureSwaggerGen(options => { options.IncludeXmlComments(Path.ChangeExtension(Assembly.GetEntryAssembly().Location, "xml")); options.OperationFilter <AuthorizationHeaderParameterOperationFilter>(); }); services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; } ) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = jwtOptions.Issuer, ValidAudience = jwtOptions.Issuer, IssuerSigningKey = new SymmetricSecurityKey( Encoding.UTF8.GetBytes(jwtOptions.SecretKey)) }; }); services.AddSession(); services.AddCors(o => o.AddPolicy("ETPolicy", builder => { builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader(); })); }
public TokenService(IOptions <JwtOptions> options) { _options = options.Value; }
public JwtOptionsProvider(IOptions <JwtSettings> options) { this.jwtOptions = new JwtOptions(options.Value.SecretId, options.Value.Expires); }
/// <summary> /// 初始化一个<see cref="JwtBearerService{TUser, TUserKey}"/>类型的新实例 /// </summary> public JwtBearerService(IServiceProvider provider) { _provider = provider; _jwtOptions = _provider.GetOSharpOptions().Jwt; }
public Startup(IConfiguration configuration) { _configuration = configuration; _jwtOptions = GetJwtOptions(); _restApiOptions = GetRestApiOptions(); }
public static IServiceCollection AddJwtAuthentication(this IServiceCollection services, JwtOptions opt) { string issuer = opt.Issuer; string key = opt.Key; services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { // validate the server that created that token ValidateIssuer = true, // ensure that the recipient of the token is authorized to receive it ValidateAudience = true, // check that the token is not expired and that the signing key of the issuer is valid ValidateLifetime = true, // verify that the key used to sign the incoming token is part of a list of trusted keys ValidateIssuerSigningKey = true, ValidIssuer = issuer, ValidAudience = issuer, IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(key)) }; }); return(services); }
public JwtTokenManager(IOptions <SiteOptions> options) { _options = options.Value.Jwt; }
public AuthController(IAccessService accessService, IOptionsSnapshot <JwtOptions> jwtOption) { _accessService = accessService; _jwtOption = jwtOption.Value; }
public TokenController(ILogger <TokenController> logger, JwtOptions jwtOptions) : base(logger) { _jwtOptions = jwtOptions; }
public AuthenticationController(UserManager <User> userManager, IOptions <JwtOptions> jwtOptions) { _userManager = userManager; _jwtOptions = jwtOptions.Value; }
public AuthController(UserManager <AppUser> userManager, IUserService userService, IOptions <JwtOptions> jwtOptions) { _userManager = userManager; _userService = userService; _jwtOptions = jwtOptions.Value; }
public AuthenticationService(UserManager <AppUser> userManager, IOptionsSnapshot <JwtOptions> jwtOptions) { this.userManager = userManager; this.jwtOptions = jwtOptions.Value; }
/// <summary> /// 创建令牌 /// </summary> /// <param name="payload">负载</param> /// <param name="options">Jwt选项配置</param> public async Task <JsonWebToken> CreateAsync(IDictionary <string, string> payload, JwtOptions options) { if (string.IsNullOrWhiteSpace(options.Secret)) { throw new ArgumentNullException(nameof(_options.Secret), $@"{nameof(options.Secret)}为Null或空字符串。请在""appsettings.json""配置""{nameof(JwtOptions)}""节点及其子节点""{nameof(JwtOptions.Secret)}"""); } var clientId = payload["clientId"] ?? Guid.NewGuid().ToString(); var claims = new List <Claim>(); foreach (var key in payload.Keys) { var tempClaim = new Claim(key, payload[key]?.ToString()); claims.Add(tempClaim); } // 生成刷新令牌 var(refreshToken, refreshExpires) = CreateToken(claims, options, JsonWebTokenType.RefreshToken); var refreshTokenStr = refreshToken; await _tokenStore.SaveRefreshTokenAsync(new RefreshToken() { ClientId = clientId, EndUtcTime = refreshExpires, Value = refreshTokenStr }); // 生成访问令牌 var(token, accessExpires) = CreateToken(claims, _options, JsonWebTokenType.AccessToken); var accessToken = new JsonWebToken() { AccessToken = token, AccessTokenUtcExpires = Conv.To <long>(accessExpires.ToJsGetTime()), RefreshToken = refreshTokenStr, RefreshUtcExpires = Conv.To <long>(refreshExpires.ToJsGetTime()) }; await _tokenStore.SaveTokenAsync(accessToken, accessExpires); return(accessToken); }
public AliseeksJwtAuthentication(IOptions <JwtOptions> jwtOptions, IRavenClient raven) { this.jwtOptions = jwtOptions.Value; this.raven = raven; }
public AccountController(UsersContext usersContext, IOptions <JwtOptions> options) { _usersContext = usersContext; _options = options.Value; }
public void ConfigureServices(IServiceCollection services) { CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture; services.AddOptions(); services.Configure <EmailOptions>(Configuration.GetSection("Email")); services.Configure <ReporterOptions>(Configuration.GetSection("Reporter")); services.Configure <JwtOptions>(Configuration.GetSection("JWT")); services.Configure <IdentityOptions>(Configuration.GetSection("Identity")); string connection = Configuration.GetConnectionString("DefaultConnection"); services.AddDbContext <TermoHubContext>(options => options.UseSqlServer(connection)); services.AddIdentity <User, IdentityRole>() .AddEntityFrameworkStores <TermoHubContext>() .AddDefaultTokenProviders(); services.AddAuthorization(options => { options.AddPolicy("DeviceOwned", policy => policy.AddRequirements(new DeviceOwnedRequirement())); }); services.AddScoped <IAuthorizationHandler, DeviceAdminHandler>(); services.AddScoped <IAuthorizationHandler, DeviceOwnerHandler>(); services.AddAuthentication() .AddCookie() .AddJwtBearer(options => { var jwt = new JwtOptions(); Configuration.Bind("JWT", jwt); options.TokenValidationParameters = new TokenValidationParameters() { IssuerSigningKey = jwt.SecurityKey, ValidateIssuerSigningKey = true, ValidIssuer = jwt.Issuer, ValidAudience = jwt.Audience, RoleClaimType = ClaimTypes.Role }; }); services.ConfigureApplicationCookie(options => { options.Cookie.Expiration = TimeSpan.FromDays(30); options.LoginPath = "/login"; options.LogoutPath = "/logout"; options.AccessDeniedPath = "/error"; }); services.AddRouting(options => { options.LowercaseUrls = true; options.ConstraintMap["devId"] = typeof(int); options.ConstraintMap["senId"] = typeof(int); }); services.AddMvc(options => { options.OutputFormatters.Add(new CsvOutputFormatter()); options.FormatterMappings.SetMediaTypeMappingForFormat("csv", "text/csv"); }); services.AddSingleton <ILastValues, MemoryCache>(); services.AddTransient <IEmailSender, DotnetEmailService>(); services.AddTransient <IAlertReporter, AlertReporter>(); }
public JwtBearerService(IServiceProvider provider) { _provider = provider; _jwtOptions = provider.GetAppSettings()?.Jwt; }
public UsersController(WarehouseContext context, JwtOptions jwtOptions, TokenValidationParameters validationParameters) { _context = context; this.jwtOptions = jwtOptions; tokenValidationParameters = validationParameters; }
/// <summary> /// 创建令牌 /// </summary> /// <param name="payload">负载</param> /// <param name="options">Jwt选项配置</param> public async Task <JsonWebToken> CreateAsync(IDictionary <string, string> payload, JwtOptions options) { if (string.IsNullOrWhiteSpace(options.Secret)) { throw new ArgumentNullException(nameof(_options.Secret), $@"{nameof(options.Secret)}为Null或空字符串。请在""appsettings.json""配置""{nameof(JwtOptions)}""节点及其子节点""{nameof(JwtOptions.Secret)}"""); } var clientId = payload.ContainsKey("clientId") ? payload["clientId"] : Guid.NewGuid().ToString(); var clientType = payload.ContainsKey("clientType") ? payload["clientType"] : "admin"; var userId = GetUserId(payload); if (userId.IsEmpty()) { throw new ArgumentException("不存在用户标识"); } var claims = Helper.ToClaims(payload); // 生成刷新令牌 var(refreshToken, refreshExpires) = Helper.CreateToken(_tokenHandler, claims, options, JsonWebTokenType.RefreshToken); var refreshTokenStr = refreshToken; await _tokenStore.SaveRefreshTokenAsync(new RefreshToken() { ClientId = clientId, EndUtcTime = refreshExpires, Value = refreshTokenStr }); // 生成访问令牌 var(token, accessExpires) = Helper.CreateToken(_tokenHandler, claims, _options, JsonWebTokenType.AccessToken); var accessToken = new JsonWebToken() { AccessToken = token, AccessTokenUtcExpires = Conv.To <long>(accessExpires.ToJsGetTime()), RefreshToken = refreshTokenStr, RefreshUtcExpires = Conv.To <long>(refreshExpires.ToJsGetTime()) }; await _tokenStore.SaveTokenAsync(accessToken, accessExpires); // 绑定用户设备令牌 await _tokenStore.BindUserDeviceTokenAsync(userId, clientType, new DeviceTokenBindInfo() { UserId = userId, DeviceId = clientId, DeviceType = clientType, Token = accessToken, }, refreshExpires); // 存储payload await _tokenPayloadStore.SaveAsync(refreshToken, payload, refreshExpires); return(accessToken); }
public UsersController(UserManager <WebApiAuthUser> userManager, IUserService userService, IOptions <JwtOptions> jwtConfig) { this.userManager = userManager; this.userService = userService; this.jwtConfig = jwtConfig.Value; }
public async Task Invoke_returns_401_if_no_match([Frozen] IUserExtractor extractor, JwtMiddleware sut, [Frozen] IServiceProvider serviceProvider, HttpContext context, JwtOptions options, IActionResultExecutor <ObjectResult> executor) { User user = null; Mock.Get(extractor).Setup(p => p.TryExtractUser(It.IsAny <HttpContext>(), out user)).Returns(false); Mock.Get(serviceProvider).Setup(p => p.GetService(typeof(IActionResultExecutor <ObjectResult>))).Returns(executor); await sut.Invoke(context, options); Mock.Get(executor).Verify(p => p.ExecuteAsync(It.IsAny <ActionContext>(), It.Is <ObjectResult>(or => or.StatusCode == 401))); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer( Configuration.GetConnectionString("DefaultConnection"))); services.AddDefaultIdentity <IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true) .AddEntityFrameworkStores <ApplicationDbContext>(); var jwtOptions = new JwtOptions(); Configuration.GetSection(nameof(JwtOptions)).Bind(jwtOptions); services.AddSingleton(jwtOptions); var tokenValidationParameters = new TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(jwtOptions.Secret)), ValidateIssuer = false, ValidateAudience = false, RequireExpirationTime = false, ValidateLifetime = true }; services.AddSingleton(tokenValidationParameters); services.AddAuthentication(x => { x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; x.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }).AddJwtBearer(x => { x.SaveToken = true; x.TokenValidationParameters = tokenValidationParameters; }); services.AddSwaggerGen(x => { x.SwaggerDoc("api", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "Contacts API", Version = "v1" }); x.ExampleFilters(); var security = new OpenApiSecurityRequirement { { new OpenApiSecurityScheme { Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" } }, new string[] {} } }; x.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { Description = "JWT Authorization header using the bearer scheme.", Name = "Authorization", In = ParameterLocation.Header, Type = SecuritySchemeType.ApiKey }); x.AddSecurityRequirement(security); var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); x.IncludeXmlComments(xmlPath); }); services.AddSwaggerExamplesFromAssemblyOf <Startup>(); services.AddScoped <IContactService, ContactService>(); services.AddScoped <ISkillService, SkillService>(); services.AddScoped <IIdentityService, IdentityService>(); services.AddSingleton <IUriService>(provider => { var accessor = provider.GetRequiredService <IHttpContextAccessor>(); var request = accessor.HttpContext.Request; var absoluteUri = string.Concat(request.Scheme, "://", request.Host.ToUriComponent(), "/"); return(new UriService(absoluteUri)); }); services.AddRazorPages(); }
public async Task Invoke_returns_200_with_token_if_match([Frozen] IUserAuthenticator authenticator, [Frozen] IUserExtractor extractor, JwtMiddleware sut, [Frozen] IServiceProvider serviceProvider, HttpContext context, JwtOptions options, IActionResultExecutor <ObjectResult> executor, User user, ClaimsIdentity identity) { Mock.Get(extractor).Setup(p => p.TryExtractUser(It.IsAny <HttpContext>(), out user)).Returns(true); Mock.Get(authenticator).Setup(p => p.TryAuthenticateUserAsync(It.IsAny <User>(), out identity)).ReturnsAsync(true); Mock.Get(serviceProvider).Setup(p => p.GetService(typeof(IActionResultExecutor <ObjectResult>))).Returns(executor); await sut.Invoke(context, options); Mock.Get(executor).Verify(p => p.ExecuteAsync(It.IsAny <ActionContext>(), It.Is <ObjectResult>(or => or.StatusCode == 200 && or.Value is TokenModel))); }
public override void PreConfigureServices(ServiceConfigurationContext context) { var configuration = context.Services.GetConfiguration(); var sckey = configuration.GetValue <string>("sckey"); var swagger = new SwaggerOptions(); var storage = new StorageOptions(); var cors = new CorsOptions(); var jwt = new JwtOptions(); var worker = new WorkerOptions(); var signature = new SignatureOptions(); var tencentCloud = new TencentCloudOptions(); var authorize = new AuthorizeOptions(); PreConfigure <SwaggerOptions>(options => { var swaggerOption = configuration.GetSection("swagger"); Configure <SwaggerOptions>(swaggerOption); options.Version = swaggerOption.GetValue <string>(nameof(options.Version)); options.Name = swaggerOption.GetValue <string>(nameof(options.Name)); options.Title = swaggerOption.GetValue <string>(nameof(options.Title)); options.Description = swaggerOption.GetValue <string>(nameof(options.Description)); options.RoutePrefix = swaggerOption.GetValue <string>(nameof(options.RoutePrefix)); options.DocumentTitle = swaggerOption.GetValue <string>(nameof(options.DocumentTitle)); swagger = options; }); PreConfigure <StorageOptions>(options => { var storageOption = configuration.GetSection("storage"); Configure <StorageOptions>(storageOption); options.Mongodb = storageOption.GetValue <string>(nameof(options.Mongodb)); options.RedisIsEnabled = storageOption.GetValue <bool>(nameof(options.RedisIsEnabled)); options.Redis = storageOption.GetValue <string>(nameof(options.Redis)); storage = options; }); PreConfigure <CorsOptions>(options => { var corsOption = configuration.GetSection("cors"); Configure <CorsOptions>(corsOption); options.PolicyName = corsOption.GetValue <string>(nameof(options.PolicyName)); options.Origins = corsOption.GetValue <string>(nameof(options.Origins)); cors = options; }); PreConfigure <JwtOptions>(options => { var jwtOption = configuration.GetSection("jwt"); Configure <JwtOptions>(jwtOption); options.Issuer = jwtOption.GetValue <string>(nameof(options.Issuer)); options.Audience = jwtOption.GetValue <string>(nameof(options.Audience)); options.SigningKey = jwtOption.GetValue <string>(nameof(options.SigningKey)); jwt = options; }); PreConfigure <WorkerOptions>(options => { var workerOption = configuration.GetSection("worker"); Configure <WorkerOptions>(workerOption); options.IsEnabled = workerOption.GetValue <bool>(nameof(options.IsEnabled)); options.Cron = workerOption.GetValue <string>(nameof(options.Cron)); worker = options; }); PreConfigure <TencentCloudOptions>(options => { var tencentCloudOption = configuration.GetSection("tencentCloud"); Configure <TencentCloudOptions>(tencentCloudOption); options.SecretId = tencentCloudOption.GetValue <string>(nameof(options.SecretId)); options.SecretKey = tencentCloudOption.GetValue <string>(nameof(options.SecretKey)); tencentCloud = options; }); PreConfigure <SignatureOptions>(options => { var signatureOption = configuration.GetSection("signature"); options.Path = signatureOption.GetValue <string>(nameof(options.Path)); foreach (var item in signatureOption.GetSection(nameof(options.Urls)).GetChildren()) { options.Urls.Add(item.GetValue <string>("url"), item.GetValue <string>("param")); } signature = options; Configure <SignatureOptions>(item => { item.Path = signature.Path; item.Urls = signature.Urls; }); }); PreConfigure <AuthorizeOptions>(options => { var authorizeOption = configuration.GetSection("authorize"); var githubOption = authorizeOption.GetSection("github"); var giteeOption = authorizeOption.GetSection("gitee"); var alipayOption = authorizeOption.GetSection("alipay"); var dingtalkOption = authorizeOption.GetSection("dingtalk"); var microsoftOption = authorizeOption.GetSection("microsoft"); var weiboOptions = authorizeOption.GetSection("weibo"); var qqOptions = authorizeOption.GetSection("qq"); Configure <AuthorizeOptions>(authorizeOption); Configure <GithubOptions>(githubOption); Configure <GiteeOptions>(giteeOption); Configure <AlipayOptions>(alipayOption); Configure <DingtalkOptions>(dingtalkOption); Configure <MicrosoftOptions>(microsoftOption); Configure <WeiboOptions>(weiboOptions); Configure <QQOptions>(qqOptions); options.Github = new GithubOptions { ClientId = githubOption.GetValue <string>(nameof(options.Github.ClientId)), ClientSecret = githubOption.GetValue <string>(nameof(options.Github.ClientSecret)), RedirectUrl = githubOption.GetValue <string>(nameof(options.Github.RedirectUrl)), Scope = githubOption.GetValue <string>(nameof(options.Github.Scope)) }; options.Gitee = new GiteeOptions { ClientId = giteeOption.GetValue <string>(nameof(options.Gitee.ClientId)), ClientSecret = giteeOption.GetValue <string>(nameof(options.Gitee.ClientSecret)), RedirectUrl = giteeOption.GetValue <string>(nameof(options.Gitee.RedirectUrl)), Scope = giteeOption.GetValue <string>(nameof(options.Gitee.Scope)) }; options.Alipay = new AlipayOptions { AppId = alipayOption.GetValue <string>(nameof(options.Alipay.AppId)), RedirectUrl = alipayOption.GetValue <string>(nameof(options.Alipay.RedirectUrl)), Scope = alipayOption.GetValue <string>(nameof(options.Alipay.Scope)), PrivateKey = alipayOption.GetValue <string>(nameof(options.Alipay.PrivateKey)), PublicKey = alipayOption.GetValue <string>(nameof(options.Alipay.PublicKey)) }; options.Dingtalk = new DingtalkOptions { AppId = dingtalkOption.GetValue <string>(nameof(options.Dingtalk.AppId)), AppSecret = dingtalkOption.GetValue <string>(nameof(options.Dingtalk.AppSecret)), RedirectUrl = dingtalkOption.GetValue <string>(nameof(options.Dingtalk.RedirectUrl)), Scope = dingtalkOption.GetValue <string>(nameof(options.Dingtalk.Scope)) }; options.Microsoft = new MicrosoftOptions { ClientId = microsoftOption.GetValue <string>(nameof(options.Microsoft.ClientId)), ClientSecret = microsoftOption.GetValue <string>(nameof(options.Microsoft.ClientSecret)), RedirectUrl = microsoftOption.GetValue <string>(nameof(options.Microsoft.RedirectUrl)), Scope = microsoftOption.GetValue <string>(nameof(options.Microsoft.Scope)) }; options.Weibo = new WeiboOptions { ClientId = weiboOptions.GetValue <string>(nameof(options.Weibo.ClientId)), ClientSecret = weiboOptions.GetValue <string>(nameof(options.Weibo.ClientSecret)), RedirectUrl = weiboOptions.GetValue <string>(nameof(options.Weibo.RedirectUrl)), Scope = weiboOptions.GetValue <string>(nameof(options.Weibo.Scope)) }; options.QQ = new QQOptions { ClientId = qqOptions.GetValue <string>(nameof(options.QQ.ClientId)), ClientSecret = qqOptions.GetValue <string>(nameof(options.QQ.ClientSecret)), RedirectUrl = qqOptions.GetValue <string>(nameof(options.QQ.RedirectUrl)), Scope = qqOptions.GetValue <string>(nameof(options.QQ.Scope)) }; authorize = options; }); PreConfigure <AppOptions>(options => { options.Swagger = swagger; options.ScKey = sckey; options.Storage = storage; options.Cors = cors; options.Jwt = jwt; options.Worker = worker; options.Signature = signature; options.TencentCloud = tencentCloud; options.Authorize = authorize; Configure <AppOptions>(item => { item.Swagger = swagger; item.ScKey = sckey; item.Storage = storage; item.Cors = cors; item.Jwt = jwt; item.Worker = worker; item.Signature = signature; item.TencentCloud = tencentCloud; item.Authorize = authorize; }); }); }
public UsersController(IOptions <JwtOptions> options) { Options = options.Value; }