public async Task <IActionResult> RunAsync( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] Credentials credentials, [CosmosDB("ProjetWeb", "Users", ConnectionStringSetting = "CosmosDB")] DocumentClient client, ILogger log) { Models.User user = null; try { user = UserUtils.GetUserFromEmail(client, credentials.Email); } catch (Exception e) { return(new NotFoundResult()); } if (user != null && _passwordProvider.IsValidPassword(credentials.Password, user.Salt, user.Password)) { return(new OkObjectResult(new BaseResponse <string>(_tokenIssuer.IssueTokenForUser(credentials, user)))); } var unauthorizedResponse = new BaseResponse <object>(); unauthorizedResponse.Errors.Add("Email ou mot de passe incorrect, veuiller réessayer."); var unauthorizedResult = new OkObjectResult(unauthorizedResponse) { StatusCode = StatusCodes.Status401Unauthorized }; return(unauthorizedResult); }