public static TokenResponse CreateFromErrorResponse(IHttpWebResponse webResponse)
        {
            if (webResponse == null)
            {
                return new TokenResponse
                {
                    Error = MsalError.ServiceReturnedError,
                    ErrorDescription = MsalErrorMessage.ServiceReturnedError
                };
            }
            StringBuilder responseStreamString = new StringBuilder();
            TokenResponse tokenResponse = null;
            using (Stream responseStream = webResponse.ResponseStream)
            {
                if (responseStream == null)
                {
                    return new TokenResponse
                    {
                        Error = MsalError.Unknown,
                        ErrorDescription = MsalErrorMessage.Unknown
                    };
                }

                try
                {
                    responseStreamString.Append(ReadStreamContent(responseStream));
                    using (MemoryStream ms = new MemoryStream(responseStreamString.ToByteArray()))
                    {
                        DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(TokenResponse));
                        tokenResponse = ((TokenResponse)serializer.ReadObject(ms));
                    }
                }
                catch (SerializationException ex)
                {
                    PlatformPlugin.Logger.Warning(null, ex.Message);
                    tokenResponse = new TokenResponse
                    {
                        Error = (webResponse.StatusCode == HttpStatusCode.ServiceUnavailable)
                            ? MsalError.ServiceUnavailable
                            : MsalError.Unknown,
                        ErrorDescription = responseStreamString.ToString()
                    };
                }
            }

            return tokenResponse;
        }
        public void GetResultTest()
        {
            TokenResponse response = new TokenResponse();
            response.IdToken =
                "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ik1uQ19WWmNBVGZNNXBPWWlKSE1iYTlnb0VLWSIsImtpZCI6Ik1uQ19WWmNBVGZNNXBPWWlKSE1iYTlnb0VLWSJ9.eyJhdWQiOiI3YzdhMmY3MC1jYWVmLTQ1YzgtOWE2Yy0wOTE2MzM1MDFkZTQiLCJpc3MiOiJodHRwczovL2xvZ2luLm1pY3Jvc29mdG9ubGluZS5jb20vODE2OTAyODYtNTA1NC00Zjk3LWI3MDgtNTQxNjU0Y2Q5MjFhL3YyLjAvIiwiaWF0IjoxNDU1NTc2MjM1LCJuYmYiOjE0NTU1NzYyMzUsImV4cCI6MTQ1NTU4MDEzNSwibmFtZSI6IkFEQUwgT2JqLUMgLSBFMkUiLCJvaWQiOiIxZTcwYThlZi1jYjIwLTQxOWMtYjhhNy1hNDJlZDJmYTIyNzciLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJlMmVAYWRhbG9iamMub25taWNyb3NvZnQuY29tIiwic3ViIjoibHJxVDlsQXQzSUlhS3hHanE2UlNReFRqN3diV3Q2RnpaMFU3NkJZMEJINCIsInRpZCI6IjgxNjkwMjg2LTUwNTQtNGY5Ny1iNzA4LTU0MTY1NGNkOTIxYSIsInZlciI6IjIuMCJ9.axS_-N3Z3b1GnZftxb6dKtMeooldoIQ_B7YrVO4CQI9xhHI1_Vl-dXfsFHBPRvIvXBEfBEehaaWq9B9P_CD5TpQXGycsYS08knHf_QpHIJ9WQbBIJ774divakx7kN6x7IxjoD1PrfRfo2QZsLLAz-1n-NHt7FwtkBQpKTDfgc6cVShy9isaJt5WoxfUM1eNo1HK_YjHj7Q5-n-XiZEbe-8m-7nqwBw86QDlLdk7dBhhCzVzXZb_5HCHI-23xZLYR34RoW7ljYEG4P8auEcML1haS4MN83VKRorMyljAIoA4YOgbfnvnlAlxRz_rtAAcjNqaUpIwzadGzd-QVbyoKPQ";
            response.AccessToken = "access-token";
            response.ExpiresIn = 3599;
            response.CorrelationId = "correlation-id";
            response.RefreshToken = "refresh-token";
            response.FamilyId = "1";
            response.Scope = "scope1 scope2";
            response.TokenType = "Bearer";

            AuthenticationResultEx resultEx = response.GetResultEx();
            Assert.IsNotNull(resultEx);
            Assert.AreEqual("access-token", resultEx.Result.Token);
            Assert.AreEqual("scope1 scope2", resultEx.Result.ScopeSet.AsSingleString());
            Assert.AreEqual("Bearer", resultEx.Result.TokenType);
        }