public async Task <IActionResult> Login([FromBody] LoginModel user) { if (user == null) { return(BadRequest("Invalid client request")); } if (_userAuthService.GetUserAuthorization(user)) { var secretKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("superSecretKey@345")); var signinCredentials = new SigningCredentials(secretKey, SecurityAlgorithms.HmacSha256); var tokeOptions = new JwtSecurityToken( issuer: "https://localhost:44321", audience: "https://localhost:44321", claims: new List <Claim>(), expires: DateTime.Now.AddMinutes(5), signingCredentials: signinCredentials ); var tokenString = new JwtSecurityTokenHandler().WriteToken(tokeOptions); return(Ok(new Token { JwtToken = tokenString })); } else { return(Unauthorized()); } }
public DeviceConfigurationResponse GetDeviceConfiguration(LoginModel user) { if (_userAuthService.GetUserAuthorization(user)) { return(_context.Client .Where(c => c.ClientCode == user.ClientCode) .Select(v => new DeviceConfigurationResponse { DeviceConfiguration = new DeviceConfiguration { ClientCode = v.ClientCode, RestUrl = v.HostUrl, PushNotificationServiceUrl = "" }, Response = true }).First()); } return(new DeviceConfigurationResponse { Response = false }); }