a better task handling
This commit is contained in:
parent
49f5c1ab0a
commit
85cfd10544
1 changed files with 21 additions and 10 deletions
|
|
@ -381,22 +381,33 @@ public class YaOAuth2Authenticator : WebRedirectAuthenticator
|
||||||
|
|
||||||
var auth = req.GetResponseAsync().ContinueWith(task =>
|
var auth = req.GetResponseAsync().ContinueWith(task =>
|
||||||
{
|
{
|
||||||
var text = task.Result.GetResponseText();
|
if (task.IsCompleted)
|
||||||
req.Abort();
|
{
|
||||||
// Parse the response
|
var text = task.Result.GetResponseText();
|
||||||
var data = text.Contains("{") ? WebEx.JsonDecode(text) : WebEx.FormDecode(text);
|
req.Abort();
|
||||||
|
// Parse the response
|
||||||
|
var data = text.Contains("{") ? WebEx.JsonDecode(text) : WebEx.FormDecode(text);
|
||||||
|
|
||||||
if (data.ContainsKey("error"))
|
if (data.ContainsKey("error"))
|
||||||
{
|
{
|
||||||
throw new AuthException("Error authenticating: " + data["error"]);
|
throw new AuthException("Error authenticating: " + data["error"]);
|
||||||
|
}
|
||||||
|
else if (data.ContainsKey("access_token"))
|
||||||
|
{
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new AuthException("Expected access_token in access token response, but did not receive one.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (data.ContainsKey("access_token"))
|
else if (task.IsFaulted)
|
||||||
{
|
{
|
||||||
return data;
|
throw new AuthException("Unexpected fault");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new AuthException("Expected access_token in access token response, but did not receive one.");
|
throw new AuthException($"Ended: {task.Status}");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue