public AuthController(UserManager <ApplicationUser> userManager, IOptions <JwtBearerTokenSettings> jwtTokenOptions, IEmailService emailService, IMapper mapper) { this.mapper = mapper; this.emailService = emailService; this.userManager = userManager; this.jwtBearerTokenSettings = jwtTokenOptions.Value; }
public AuthController(IOptions <JwtBearerTokenSettings> jwtTokenOptions, UserManager <User> userManager, RoleManager <IdentityRole> roleManager, RefreshTokenRepository refreshTokenRepository) { this.jwtBearerTokenSettings = jwtTokenOptions.Value; this.userManager = userManager; this.roleManager = roleManager; this.refreshTokenRepository = refreshTokenRepository; }
public AuthController(IOptions <JwtBearerTokenSettings> jwtTokenOptions, UserManager <IdentityUser> userManager, RoleManager <IdentityRole> roleManager, ApplicationDbContext dbContext) { this.jwtBearerTokenSettings = jwtTokenOptions.Value; this.userManager = userManager; this.roleManager = roleManager; this._dbContext = dbContext; }
public AuthController(IOptions <JwtBearerTokenSettings> jwtBearerTokenSettings, UserManager <User> userManager, RoleManager <IdentityRole> roleManager, IMapper mapper) { _jwtBearerTokenSettings = jwtBearerTokenSettings.Value; _userManager = userManager; _roleManager = roleManager; _mapper = mapper; }
public UserController(UserManager <AppUser> userManager, SignInManager <AppUser> signInManager, RoleManager <IdentityRole> roleManager, IOptions <JwtBearerTokenSettings> jwtTokenOptions, ILogger <UserController> logger) { this.userManager = userManager; this.signInManager = signInManager; this.roleManager = roleManager; this.logger = logger; this.jwtBearerTokenSettings = jwtTokenOptions.Value; }
public AuthenticationService( IOptions <JwtBearerTokenSettings> jwtTokenOptions, UserManager <ApplicationUser> userManager, IMapper mapper) { _jwtBearerTokenSettings = jwtTokenOptions.Value; _userManager = userManager; _mapper = mapper; }
public AuthController( IOptions <JwtBearerTokenSettings> jwtTokenOptions, IUserService userService, UserManager <IdentityUser> userManager) { _userService = userService; _jwtBearerTokenSettings = jwtTokenOptions.Value; _userManager = userManager; }
public static void ConfigureIdentity(this IServiceCollection services, JwtBearerTokenSettings jwtSettings, bool isDevelopment) { services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(options => { if (isDevelopment) { options.RequireHttpsMetadata = false; } options.TokenValidationParameters = new TokenValidationParameters { ClockSkew = TimeSpan.FromMinutes(2), IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(jwtSettings.SecretKey)), RequireExpirationTime = true, RequireSignedTokens = true, ValidateIssuerSigningKey = true, ValidateIssuer = true, ValidateAudience = false, ValidateLifetime = true, NameClaimType = "name", RoleClaimType = "role", ValidIssuer = jwtSettings.Issuer, ValidAudience = jwtSettings.Audience }; options.Events = new JwtBearerEvents { OnAuthenticationFailed = context => { if (context.Exception.GetType() == typeof(SecurityTokenExpiredException)) { context.Response.Headers.Add("Token-Expired", "true"); } else { context.Response.Headers.Add("Token-Error", context.Exception.Message); } return(Task.CompletedTask); }, OnTokenValidated = context => { return(Task.CompletedTask); } }; }); }
public AuthService( UserManager <DbUser> userManager, SignInManager <DbUser> signInManager, EmailService emailService, AppDbContext context, IOptions <JwtBearerTokenSettings> jwtBearerTokenOptions) { this.userManager = userManager; this.signInManager = signInManager; this.emailService = emailService; this.context = context; jwtBearerTokenSettings = jwtBearerTokenOptions.Value; }
private string GenerateToken(IdentityUser identityUser, JwtBearerTokenSettings jwtBearerTokenSettings) { var tokenHandler = new JwtSecurityTokenHandler(); var key = Encoding.ASCII.GetBytes(jwtBearerTokenSettings.SecretKey); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, identityUser.UserName), new Claim(ClaimTypes.Email, identityUser.Email) }), Expires = DateTime.UtcNow.AddSeconds(jwtBearerTokenSettings.ExpiryTimeInSeconds), SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature), Audience = jwtBearerTokenSettings.Audience, Issuer = jwtBearerTokenSettings.Issuer }; var securityToken = tokenHandler.CreateToken(tokenDescriptor); var token = tokenHandler.WriteToken(securityToken); return(token); }
public AuthController(IOptions <JwtBearerTokenSettings> jwtTokenOptions, UserManager <User> userManager, RepositoryContext dbContext, ILogger <AuthController> logger, IHubContext <NotifHub> hubContext, RoleManager <Role> roleManager, IUserConnectionManager userConnectionManager, IMapper mapper) { _jwtBearerTokenSettings = jwtTokenOptions.Value; _userManager = userManager; _dbContext = dbContext; _userConnectionManager = userConnectionManager; _roleManager = roleManager; _mapper = mapper; _logger = logger; _hubContext = hubContext; }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddCors(options => { options.AddPolicy("localhost", builder => { builder.WithOrigins("https://localhost:4200", "http://localhost:4200"); builder.AllowAnyMethod(); builder.AllowAnyHeader(); }); }); services.AddControllers(); IConfigurationSection jwtSection = Configuration.GetSection("JwtBearerTokenSettings"); JwtBearerTokenSettings jwtBearerTokenSettings = jwtSection.Get <JwtBearerTokenSettings>(); services.AddSingleton <ITokenService, TokenService>(sp => new TokenService(jwtSection.Get <JwtBearerTokenSettings>().SecretKey)); IConfigurationSection dbSection = Configuration.GetSection("DbConnectionSettings"); DbConnectionSettings dbConnectionSettings = dbSection.Get <DbConnectionSettings>(); string connectionString = dbSection.Get <DbConnectionSettings>().SqlServerConnectionString; services.AddSingleton <DbProviderFactory>(sp => SqlClientFactory.Instance); services.AddSingleton(sp => new ConnectionInfo(connectionString)); services.AddSingleton <Connection>(); services.AddSingleton <AuthService>(); services.AddSingleton <UserService>(); services.AddSingleton <RoleService>(); services.AddSingleton <GameService>(); services.AddSingleton <RuleService>(); services.AddSingleton <TimeControlService>(); services.AddSingleton <StatisticService>(); }
public AuthController(IOptions <JwtBearerTokenSettings> jwtTokenOptions, UserManager <User> userManager) { _userManager = userManager; _jwtBearerTokenSettings = jwtTokenOptions.Value; }
public AuthController(IOptions <JwtBearerTokenSettings> jwtTokenOptions, UserManager <IdentityUser> userManager) { this.jwtBearerTokenSettings = jwtTokenOptions.Value; this.userManager = userManager; }
public JwtService(IOptions <JwtBearerTokenSettings> jwtBearerTokenSettings) { _jwtBearerTokenSettings = jwtBearerTokenSettings.Value; }
public AuthController(IOptions <JwtBearerTokenSettings> jwtTokenOptions, UserManager <ApplicationUser> userManager, ApplicationDbContext dbContext) { this.jwtBearerTokenSettings = jwtTokenOptions.Value; this.userManager = userManager; this.dbContext = dbContext; }
public AccountController(IOptions <JwtBearerTokenSettings> jwtTokenOptions, UserManager <AppUser> userManager, SignInManager <AppUser> signInManager) { this.jwtBearerTokenSettings = jwtTokenOptions.Value; _signInManager = signInManager; _userManager = userManager; }
public LoginController(IOptions <JwtBearerTokenSettings> jwtTokenOptions, UserManager <IdentityUser> userManager, UnitOfWork unitOfWork) { this.unitOfWork = unitOfWork; this.userManager = userManager; this.jwtBearerTokenSettings = jwtTokenOptions.Value; }