如何从AdalException检索JSON响应? [英] How can I retrieve the JSON response from an AdalException?
问题描述
如果我从服务中调用AuthenticationContext.AcquireToken,则在某些情况下会引发AdalException,因为我发送的令牌缺少必填声明。我调用AcquireToken时的响应中包含缺少声明的JSON。我希望能够获取该JSON(特别是缺少的声明信息),以便尝试用该丢失的声明重新授权用户。
If I call AuthenticationContext.AcquireToken from our service, it throws an AdalException in a certain situation because the token I’m sending is missing a required claim. The response from when I call AcquireToken contains JSON in it with the claim that is missing. I want to be able to get at that JSON (specifically the missing claim information) so I can attempt to reauthorize the user with that missing claim.
一旦我发现AdalException,通过调用AcquireToken,如何获得JSON响应以找出缺少的声明?如果我尝试从AdalException上的innerException获取响应流:
Once I catch the AdalException from calling AcquireToken, how can I get at the JSON response to find out which claim was missing? If I try to get the response stream from the innerException on the AdalException:
catch (AdalException ex)
{
WebException webex = (WebException)ex.InnerException;
WebResponse response = webex.Response;
Stream responseStream = response.GetResponseStream();
...
...然后我得到的responseStream包含CanRead,CanSeek和CanWrite属性全部设置为false。因此,我不确定如何检索丢失的Claims参数,因为我实际上无法从该流中读取。
… then the responseStream I get has the CanRead, CanSeek, and CanWrite properties all set to false. Consequently, I’m not sure how to retrieve the missing claims parameter since I can’t actually read from that stream.
推荐答案
返回整个服务器JSON响应的修复是在ADAL v3中进行的。 Github链接:- https://github.com/AzureAD/ azure-activedirectory-library-for-dotnet / issues / 513
在ADAL v2中尚不可用。
The fix to return the entire server JSON response is made in ADAL v3. Github Link :- https://github.com/AzureAD/azure-activedirectory-library-for-dotnet/issues/513 It is not yet available in ADAL v2.
这篇关于如何从AdalException检索JSON响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!