public async Task <ActionResult <object> > Get(string path) { try { HttpClient client = factory.CreateClient(); client.BaseAddress = new Uri("https://graph.microsoft.com"); var accessToken = await graphTokenService.AccessTokenForCurrentUser(new string[] { "openid" }); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); var uri = "https://graph.microsoft.com/" + path; logger.LogInformation("GET {uri}", uri); HttpResponseMessage response = await client.GetAsync(uri); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); return(Ok(JObject.Parse(content).ToObject <dynamic>())); } else { var msg = path + await response.Content.ReadAsStringAsync(); return(StatusCode((int)response.StatusCode, msg)); } } catch (Exception e) { return(Problem(detail: e.Message, statusCode: (int)HttpStatusCode.InternalServerError, title: "Server Error")); } }
protected override async Task <AuthenticateResult> HandleAuthenticateAsync() { var accessToken = await tokenService.AccessTokenForCurrentUser(new[] { "profile" }); JwtSecurityToken token = new JwtSecurityTokenHandler().ReadJwtToken(accessToken); var principal = new ClaimsPrincipal(new ClaimsIdentity(token.Claims, Scheme.Name)); var ticket = new AuthenticationTicket(principal, Scheme.Name); return(AuthenticateResult.Success(ticket)); }