public TokenController(IOptions <ApiConfiguration> apiConfiguration, IJwtTokenBuilder jwtTokenBuilder, UserManager <ApplicationUser> userManager ) { _jwtTokenBuilder = jwtTokenBuilder; _userManager = userManager; _apiConfiguration = apiConfiguration; }
public AuthController(IJwtTokenBuilder tokenBuilder, IOptions <JwtTokenOptions> jwtOptions, UserManager <IdentityUser> userManager, SignInManager <IdentityUser> signInManager, Tenants tenants) { _tokenBuilder = tokenBuilder; _jwtOptions = jwtOptions.Value; _userManager = userManager; _signInManager = signInManager; _tenants = tenants; }
public IdentityService(IDapper dapper, IJwtTokenBuilder tokenBuilder) { Dapper = dapper; TokenBuilder = tokenBuilder; }
public AuthService(IJwtTokenBuilder jwtTokenBuilder, IUnitOfWork unitOfWork) { _jwtTokenBuilder = jwtTokenBuilder; this.unitOfWork = unitOfWork; }
public async Task <IActionResult> Create([FromBody] ApiUser inputModel) { try { var user = await _userManager.FindByNameAsync(inputModel.Username); if (user == null) { return(Unauthorized()); } if (!int.TryParse(_apiConfiguration.Value.DefaultTimeout, out int defaultTimeout)) { defaultTimeout = 60; } if (TimeZoneInfo.Local.IsDaylightSavingTime(DateTime.Now)) { defaultTimeout += 60; } if (!await _userManager.CheckPasswordAsync(user, inputModel.Password)) { return(Unauthorized()); } var userclaims = await _userManager.GetClaimsAsync(user); var roles = await _userManager.GetRolesAsync(user); IJwtTokenBuilder tb = null; if (roles.Where(x => x == "Administrator").Count() > 0) { //return Ok(GenerateJWT(user)); tb = _jwtTokenBuilder.AddSecurityKey(JwtSecurityKey.Create("ZackTechSecretKey")) .AddSubject(inputModel.Username) .AddIssuer("ZackTechSecurityBearer") .AddAudience("ZackTechSecurityBearer") //.AddClaim(JwtRegisteredClaimNames.Sub, user.UserName) .AddClaim("AdministratorId", "") //.AddClaim("SeniorLibrarianId", "333") .AddClaim("MembershipId", "111") .AddExpiry(defaultTimeout); } else { tb = _jwtTokenBuilder.AddSecurityKey(JwtSecurityKey.Create("ZackTechSecretKey")) .AddSubject(inputModel.Username) .AddIssuer("ZackTechSecurityBearer") .AddAudience("ZackTechSecurityBearer") //.AddClaim(JwtRegisteredClaimNames.Sub, user.UserName) .AddClaim("MembershipId", "111") .AddExpiry(defaultTimeout); } foreach (var claim in userclaims) { tb.AddClaim(claim.Value, claim.Value); } var token = tb.Build(); return(Ok(token.Value)); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); ModelState.AddModelError("Login Error", ex.Message); return(BadRequest(ModelState)); } }
public ValuesController(IJwtTokenBuilder tokenBuilder) { JwtTokenBuilder = tokenBuilder; }