public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req, [Table("PublicKeys")] CloudTable cloudTable, ILogger log) { log.LogInformation("Login requestes"); FunctionContext <dynamic> fc = new FunctionContext <dynamic>(log, req, cloudTable); string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); dynamic data = JsonConvert.DeserializeObject(requestBody); if (data == null) { return(new BadRequestObjectResult("No Payload available")); } fc.PayLoad = data; string username = data.username; string password = data.password; if (String.IsNullOrEmpty(username) || String.IsNullOrEmpty(password)) { return(new BadRequestObjectResult("Nix username or password")); } string ctURL = System.Environment.GetEnvironmentVariable("CT_URL"); CTLoginService service = new CTLoginService(ctURL); LoginResult lr = await service.DoLogin(username, password, httpClient); log.LogInformation("Result: " + lr.Error); if (!lr.Error) { CTWhoami cTWhoami = await service.GetWhoAmi(lr.SetCookieHeader, httpClient); List <CTGroupContainer> groups = await service.GetGroups(lr.SetCookieHeader, cTWhoami.id, httpClient); List <string> scopes = groups.Select(gc => "ct_group_" + gc.group.domainIdentifier).ToList(); Tokens tokens = await jwtService.BuildJWTToken(cTWhoami, scopes, fc); return(new OkObjectResult(tokens)); } return(new UnauthorizedResult()); }