private async Task <IActionResult> SignInExistingUser(ApplicationUser user, string returnUrl) { try { var userRoles = await _userManager.GetRolesAsync(user); var token = JWTManager.GenerateToken(user, userRoles, _tokenConfig); //await InvalidateToken(Request.Headers[AuthHeaderName]); //var userClaims = await _claimService.ValidClaimsForUserAsync(user.Id); string infoAsJson = JsonConvert.SerializeObject(new { token = new JwtSecurityTokenHandler().WriteToken(token), userName = user.UserName, userEmail = user.Email, userId = user.Id, tokenExpiration = token.ValidTo, roles = userRoles, //userClaims = _claimService.ClaimsAsDictionary(userClaims) }); returnUrl += $"?auth={infoAsJson}"; return(Redirect(returnUrl)); } catch { //await AuditService.EditContentAndUserAsync(AuditId, AuditContentType.Activity, // AuditMessages.Failure.ToString(), user.Id, user.UserName); returnUrl += $"?error=true"; return(Redirect(returnUrl)); }; }
public IHttpActionResult Login([FromBody] UserModel user) { var entity = _userRepo.First(new Specification <User>(s => s.Email == user.Email)); var passwordHash = _encryptionService.CreatePasswordHash(user.Password, entity.PasswordSalt); if (user.Password != entity.Password) { return(BadRequest()); } if (user != null) { using (var uow = _unitOfWork.Create()) { entity.PushToken = user.TokenPush; } return(Ok( new { token = JWTManager.GenerateToken(entity), name = entity.UserName })); } else { return(BadRequest()); } }
public string Get(string aadToken) { if (CheckUser(aadToken)) { return(JWTManager.GenerateToken(email)); } throw new HttpResponseException(HttpStatusCode.Unauthorized); }
public string GetSession(string username, string password) { User u1 = new User(); if ((u1 = CheckUser(username, password)) != null) { return(JWTManager.GenerateToken(u1.Username, u1.Role)); } throw new HttpResponseException(HttpStatusCode.Unauthorized); }
public IHttpActionResult GetToken(string username, string password) { if (CheckUser(username, password)) { string token = (JWTManager.GenerateToken(username)); var principal = JWTManager.AuthenticateJwtToken(token); var i = principal.Result.Identity.Name; return(Ok((token, i))); } return(StatusCode(HttpStatusCode.Unauthorized)); }
public HttpResponseMessage Login([FromBody] LoginCredentials loginCredentials) { var userResult = _securityOrchestration.Login(loginCredentials); if (userResult == null) { return(Request.CreateResponse(HttpStatusCode.Forbidden)); } var newJwtToken = JWTManager.GenerateToken(userResult); return(Request.CreateResponse(HttpStatusCode.OK, newJwtToken)); }
public JsonResult GetToken(int clientId, string userName, string password) { try { log.Info("GetToken method called for client id: " + clientId + " and username: "******"true", message = "Authentication successful", access_token = encodedJwt, expires_in_seconds = (int)TimeSpan.FromMinutes(60).TotalSeconds }; log.Info("Token generated for client id:" + clientId + " and username: "******"false", message = "Not authenticated", access_token = "", expires_in_seconds = 0 }; log.Info("Client not authenticated client id:" + clientId + " and username: "******"Token generation failed for client id:" + clientId + " and username: "******"false", message = "Some error occured", access_token = "", expires_in_seconds = 0 }; return(Json(responseJson)); } }
public IResult LogIn(User user, string password) { if (user.Password != EncryptProvider.Md5(password)) { return(new ErrorResult(Messages.User.NotLogIn)); } var token = JWTManager.GenerateToken(user); try { var db = cache.GetDatabase(0); db.StringSet($"{token}_user", JsonConvert.SerializeObject(user), TimeSpan.FromDays(1)); } catch (System.Exception) { return(new ErrorResult(Messages.User.NotLogIn)); } return(new SuccessResult(token)); }
public string GetToken(LoginModel loginModel) { var userInfo = context.Users.FirstOrDefault(f => f.UserName == loginModel.UserName); if (userInfo == null) { throw new UnauthorizedAccessException(); } if (userInfo.PasswordHash != loginModel.Password) { throw new UnauthorizedAccessException(); } var companyInfo = context.CompanyInfo.FirstOrDefault(f => f.ID == userInfo.CompanyId); var token = JWTManager.GenerateToken(userInfo, companyInfo); return(token); }
public async Task <IActionResult> Login([FromBody] AuthData authData) { var tokenString = _jwtManager.GenerateToken("d", "d"); return(Ok(new { Token = tokenString })); }