Trying to fix all Imgur related tickets for the 1.2.10 version: BUG-2241, BUG-2239, BUG-2236, BUG-2235, BUG-2231

[skip ci]
This commit is contained in:
Krom, Robertus 2017-07-31 08:20:07 +02:00
parent 9a402f82cc
commit 2f824069e0
4 changed files with 39 additions and 5 deletions

View file

@ -1012,6 +1012,37 @@ Greenshot received information from CloudServiceName. You can close this browser
settings.Code = null;
}
/// <summary>
/// Used to update the settings with the callback information
/// </summary>
/// <param name="settings">OAuth2Settings</param>
/// <param name="callbackParameters">IDictionary</param>
/// <returns>true if the access token is already in the callback</returns>
private static bool UpdateFromCallback(OAuth2Settings settings, IDictionary<string, string> callbackParameters)
{
if (!callbackParameters.ContainsKey(AccessToken))
{
return false;
}
if (callbackParameters.ContainsKey(RefreshToken))
{
// Refresh the refresh token :)
settings.RefreshToken = callbackParameters[RefreshToken];
}
var expiresIn = callbackParameters[ExpiresIn];
settings.AccessTokenExpires = DateTimeOffset.MaxValue;
if (expiresIn != null)
{
double seconds;
if (double.TryParse(expiresIn, out seconds))
{
settings.AccessTokenExpires = DateTimeOffset.Now.AddSeconds(seconds);
}
}
settings.AccessToken = callbackParameters[AccessToken];
return true;
}
/// <summary>
/// Go out and retrieve a new access token via refresh-token with the TokenUrl in the settings
/// Will upate the access token, refresh token, expire date
@ -1109,6 +1140,7 @@ Greenshot received information from CloudServiceName. You can close this browser
GenerateRefreshToken(settings);
return true;
}
return UpdateFromCallback(settings, loginForm.CallbackParameters);
}
return false;
}