cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
We’re having some trouble with our services currently. We’re working to fix the problem as quickly as we can. We’ll share another update shortly. For the latest information visit here.

Dropbox Sign API

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Invalid_Grant whlie generating Access Token using saved Refresh token in Dropbox Sign .NET SDK

Invalid_Grant whlie generating Access Token using saved Refresh token in Dropbox Sign .NET SDK

gagsbh
Helpful | Level 5

Hello @Greg-DB ,

 

I am using the following Dropbox Sign .NET SDK code in my project to generate Dropbox Sign Access token using previously saved Refresh token.

 

 public async Task<TokenResponse> GetRefreshToken(TokenResponse tokenResponse)
        {
            TokenResponse tokenResponse2 = new TokenResponse();
            string errorlog = ConfigurationManager2.AppSettings("ErrorLog");
 
            var config = new Configuration();
            var oAuthApi = new OAuthApi(config);
           
            try
            {
                var data = new OAuthTokenRefreshRequest(refreshToken: tokenResponse.RefreshToken);
 
                var result = await oAuthApi.OauthTokenRefreshAsync(data);
                if (result != null)
                {
                    tokenResponse2.Expires = result.ExpiresIn;
                    tokenResponse2.AcquireTime = DateTime.Now;
                    tokenResponse2.AccessToken = result.AccessToken;
                    tokenResponse2.RefreshToken = result.RefreshToken; 
                    tokenResponse2.AcquireTime = DateTime.UtcNow;                  
                }               
 
                return tokenResponse2;
            }            
            catch (ApiException ex)
            {                
                    File.AppendAllText(errorlog, "\r\n\r\n" + "nGetRefreshToken: - Error");
                    File.AppendAllText(errorlog, "\r\nException when calling Dropbox Sign API: " + ex.Message);
                    File.AppendAllText(errorlog, "\r\nStatus Code: " + ex.ErrorCode);
                    File.AppendAllText(errorlog, "\r\nStack Trace: " +  ex.StackTrace);
             
    throw ex;
            }
            catch (Exception ex)
            {
                File.AppendAllText(errorlog, "\r\nGetRefreshToken - Error");
                File.AppendAllText(errorlog, "\r\n" + ex.Message + "\r\n" + ex.StackTrace);
            }
 
            return tokenResponse;
        }

 

I am getting the following Error Message and Stack Trace.
 
Error converting value "invalid_grant" to type 'Dropbox.Sign.Model.ErrorResponseError'. Path 'error', line 1, position 24.
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
at Dropbox.Sign.Client.Configuration.<>c.<.cctor>b__78_0(String methodName, IApiResponse response)
at Dropbox.Sign.Api.OAuthApi.OauthTokenRefreshWithHttpInfoAsync(OAuthTokenRefreshRequest oAuthTokenRefreshRequest, Int32 operationIndex, CancellationToken cancellationToken)
at Dropbox.Sign.Api.OAuthApi.OauthTokenRefreshAsync(OAuthTokenRefreshRequest oAuthTokenRefreshRequest, Int32 operationIndex, CancellationToken cancellationToken)
at SGCloudMigration.Business.DropboxSignUtility.GetRefreshToken(TokenResponse tokenResponse, String relationshipname) in D:\SG Cloud Migration\SGCloudMigration.Business.Core\DropboxSignUtility.cs:line 364
 
Please  help.
 
Thanks,
Gagan
1 Accepted Solution

Accepted Solutions

Spencer H
Dropbox Staff

[Cross-linking for reference: https://stackoverflow.com/questions/78296262/why-am-i-getting-invalid-grant-error-while-using-refres... ]

 

Hi Gagan,

Thank you for reaching out, it looks like you are receiving an invalid_grant error. This error typically occurs when using a stored refresh token and one of the following is true: 

 - Scopes for the OAuth API app have changed

 - The user revoked authorization to the OAuth API app
 - The OAuth API app is approved multiple times by the same user—this will cause the previous authorization to reset and a new refresh token to be generated.

If any of these actions have occurred, please try completing the authorization process again for the user to generate a new access_token and refresh_token. Try using the new refresh_token to generate any new access_token after the initial access_token expires. Please see our OAuth Walkthrough documentation for more details.

If the issue persists, please submit a support request, along with the code snippet you just provided, so we can further assist you in determining why that error is being thrown. Thanks!

View solution in original post

2 Replies 2

Spencer H
Dropbox Staff

[Cross-linking for reference: https://stackoverflow.com/questions/78296262/why-am-i-getting-invalid-grant-error-while-using-refres... ]

 

Hi Gagan,

Thank you for reaching out, it looks like you are receiving an invalid_grant error. This error typically occurs when using a stored refresh token and one of the following is true: 

 - Scopes for the OAuth API app have changed

 - The user revoked authorization to the OAuth API app
 - The OAuth API app is approved multiple times by the same user—this will cause the previous authorization to reset and a new refresh token to be generated.

If any of these actions have occurred, please try completing the authorization process again for the user to generate a new access_token and refresh_token. Try using the new refresh_token to generate any new access_token after the initial access_token expires. Please see our OAuth Walkthrough documentation for more details.

If the issue persists, please submit a support request, along with the code snippet you just provided, so we can further assist you in determining why that error is being thrown. Thanks!

gagsbh
Helpful | Level 5
Go to solution

Thank you for the reply.

For me, the issue was due to:

- The OAuth API app is approved multiple times by the same user—this will cause the previous authorization to reset and a new refresh token to be generated.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    gagsbh Helpful | Level 5
  • User avatar
    Spencer H Dropbox Staff
What do Dropbox user levels mean?