I am trying to set my dropbox configuration to TokenAccessType Offline on my page, but I am getting erros on the "DropboxOAuth2Helper.ProcessCodeFlowAsync"
I get: Dropbox.Api.OAuth2Exception: 'invalid_grant'
for error description I got: redirect_uri mismatch
after I got the page to enter my credentials I call this method:
public async Task<ActionResult> DropboxRedirect(string code, string state)
{
try
{
var connectState = PantherCache.Get(_identityService.User.Guid + "_dropBoxConnectionState").Replace("\"", "");
if (connectState != state)
{
SessionVars.AddNotification(User.Identity.Name, new Notification
{
Type = NotificationType.error,
Text = "There was an error connecting to Dropbox."
});
return this.RedirectToAction("BoxSync");
}
var appKey = ConfigurationManager.AppSettings["dropbox.clientId"].ToString();
var appSecret = ConfigurationManager.AppSettings["dropbox.clientSecret"].ToString();
string redirectUri = Url.Action("DropboxRedirect", "Settings", new { code = code, state = state }, this.Request.Url.Scheme);
Uri responseUri = new Uri(redirectUri);
var response = await DropboxOAuth2Helper.ProcessCodeFlowAsync(responseUri, appKey, appSecret, redirectUri.ToString(), state: connectState);
// OAuth2Response response = await DropboxOAuth2Helper.ProcessCodeFlowAsync(responseUri, appKey, appSecret, state: connectState);
var tenant = await _unitOfWork.TenantRepository.GetTenantByTenantGuid(_identityService.Tenant.Guid).FirstAsync();
var isDropboxIntegrationEnabled = tenant.IsDropboxIntegrationEnabled;
tenant.DropboxAuthToken = Encryptor.Encrypt(response.AccessToken);
tenant.IsDropboxIntegrationEnabled = true;
var res = await _unitOfWork.TenantRepository.InsertOrUpdateAndSaveAsync(tenant);
//if the tenant was not integrated to drop box prior to the update
if (!isDropboxIntegrationEnabled)
{
QueueService.SendDropboxSyncQueueMessage(tenant.Id, null, null, Model.QueueModels.BoxSyncMessageType.InitSync, _identityService.User.Guid);
}
_identityService.ResetSessionVariablesFromCurrentContext(_identityService.User.Name, true, true);
SessionVars.AddNotification(User.Identity.Name, new Notification
{
Type = NotificationType.success,
Text = "This account is now connected to Dropbox!"
});
return this.RedirectToAction("BoxSync");
}
catch (Exception e)
{
SessionVars.AddNotification(User.Identity.Name, new Notification
{
Type = NotificationType.error,
Text = "DropBox Authentication Error. Please try again later or contact support."
});
ErrorHelper.LogErrorManually(e);
return this.RedirectToAction("BoxSync");
}
}
I got the error on this line:
var response = await DropboxOAuth2Helper.ProcessCodeFlowAsync(responseUri, appKey, appSecret, redirectUri.ToString(), state: connectState);
currently my ResponseUri values are: "https://localhost:44383/Settings/DropboxRedirect?code=qX6NI6vbQh4AAAAAAAAAbCeVf-D8ZK916ZSKjp7oc64&state=afeb873a8cb7437dac1da70a59690dab"
I am creating my responseUri wrong? how should I create it?