Extended OAuthHelper to work better with the Dropbox OAuth implementation

This commit is contained in:
Kenneth Skovhede
2016-09-08 15:03:16 +02:00
parent 3eb9b4b8d7
commit 5a03b573cd
@@ -25,7 +25,7 @@ namespace Duplicati.Library
{
private string m_token;
private string m_authid;
private DateTime m_tokenExpires = DateTime.UtcNow;
private DateTime m_tokenExpires = DateTime.UtcNow;
private static string _override_server = null;
@@ -45,7 +45,14 @@ namespace Duplicati.Library
return string.Format(addr.ToString(), modulename);
}
/// <summary>
/// Set to true to automatically add the Authorization header to requets
/// </summary>
public bool AutoAuthHeader { get; set; }
/// <summary>
/// Set to true if the provider does not use refresh tokens, but only access tokens
/// </summary>
public bool AccessTokenOnly { get; set; }
public OAuthHelper(string authid, string servicename, string useragent = null)
: base(useragent)
@@ -78,6 +85,9 @@ namespace Duplicati.Library
{
get
{
if (AccessTokenOnly)
return m_authid;
if (m_token == null || m_tokenExpires < DateTime.UtcNow)
{
var retries = 0;
@@ -132,6 +142,19 @@ namespace Duplicati.Library
}
}
public void ThrowOverQuotaError()
{
throw new Exception(Strings.OAuthHelper.OverQuotaError);
}
public void ThrowAuthException(string msg, Exception ex)
{
if (ex == null)
throw new Exception(Strings.OAuthHelper.AuthorizationFailure(msg, OAuthLoginUrl));
else
throw new Exception(Strings.OAuthHelper.AuthorizationFailure(msg, OAuthLoginUrl), ex);
}
private class OAuth_Service_Response