public void ExtractClaimChallengeFromHeader_IncorrectError_ReturnNull() { // Arrange HttpResponseMessage httpResponse = CreateClaimsHttpErrorResponse(); // Act & Assert Assert.IsNull(WwwAuthenticateParameters.GetClaimChallengeFromResponseHeaders(httpResponse.Headers)); }
public void ExtractEncodedClaimChallengeFromHeader() { // Arrange HttpResponseMessage httpResponse = CreateClaimsHttpResponse(EncodedClaims); // Act string extractedClaims = WwwAuthenticateParameters.GetClaimChallengeFromResponseHeaders(httpResponse.Headers); // Assert Assert.AreEqual(DecodedClaims, extractedClaims); }
public async Task <IActionResult> Profile() { User currentUser = null; try { currentUser = await _graphServiceClient.Me.Request().GetAsync(); } // Catch CAE exception from Graph SDK catch (ServiceException svcex) when(svcex.Message.Contains("Continuous access evaluation resulted in claims challenge")) { try { Console.WriteLine($"{svcex}"); string claimChallenge = WwwAuthenticateParameters.GetClaimChallengeFromResponseHeaders(svcex.ResponseHeaders); _consentHandler.ChallengeUser(_graphScopes, claimChallenge); return(new EmptyResult()); } catch (Exception ex2) { _consentHandler.HandleException(ex2); } } try { // Get user photo using (var photoStream = await _graphServiceClient.Me.Photo.Content.Request().GetAsync()) { byte[] photoByte = ((MemoryStream)photoStream).ToArray(); ViewData["Photo"] = Convert.ToBase64String(photoByte); } } catch (Exception pex) { Console.WriteLine($"{pex.Message}"); ViewData["Photo"] = null; } ViewData["Me"] = currentUser; return(View()); }