Skip to content

Instantly share code, notes, and snippets.

@IntuitDeveloperRelations
Last active December 3, 2017 01:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IntuitDeveloperRelations/7259345 to your computer and use it in GitHub Desktop.
Save IntuitDeveloperRelations/7259345 to your computer and use it in GitHub Desktop.
.NET DevDefined IPP Platform Reconnect Call
using DevDefined.OAuth.Consumer;
using DevDefined.OAuth.Framework;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;
using System.Net;
namespace IPPQbApiConsoleApp
{
static class SampleCalls
{
public static string ReconnectRealm(string consumerKey, string consumerSecret, string accessToken, string accessTokenSecret)
{
HttpWebRequest httpWebRequest = WebRequest.Create("https://appcenter.intuit.com/api/v1/Connection/Reconnect") as HttpWebRequest;
httpWebRequest.Method = "GET";
httpWebRequest.Headers.Add("Authorization", GetDevDefinedOAuthHeader(httpWebRequest, consumerKey, consumerSecret, accessToken, accessTokenSecret));
UTF8Encoding encoding = new UTF8Encoding();
HttpWebResponse httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;
using (Stream data = httpWebResponse.GetResponseStream())
{
//return XML response
return new StreamReader(data).ReadToEnd();
}
}
static string GetDevDefinedOAuthHeader(HttpWebRequest webRequest, string consumerKey, string consumerSecret, string accessToken, string accessTokenSecret)
{
OAuthConsumerContext consumerContext = new OAuthConsumerContext
{
ConsumerKey = consumerKey,
ConsumerSecret = consumerSecret,
SignatureMethod = SignatureMethod.HmacSha1,
UseHeaderForOAuthParameters = true
};
consumerContext.UseHeaderForOAuthParameters = true;
//URIs not used - we already have Oauth tokens
OAuthSession oSession = new OAuthSession(consumerContext, "https://www.example.com",
"https://www.example.com",
"https://www.example.com");
oSession.AccessToken = new TokenBase
{
Token = accessToken,
ConsumerKey = consumerKey,
TokenSecret = accessTokenSecret
};
IConsumerRequest consumerRequest = oSession.Request();
consumerRequest = ConsumerRequestExtensions.ForMethod(consumerRequest, webRequest.Method);
consumerRequest = ConsumerRequestExtensions.ForUri(consumerRequest, webRequest.RequestUri);
consumerRequest = consumerRequest.SignWithToken();
return consumerRequest.Context.GenerateOAuthParametersForHeader();
}
}
}
#endregion
@sagarvyas
Copy link

I am using this code to Renew access token for Intuit QuickBooks integration.

but, I am unable to test this code as intuit renew its access token only after 150 days from token creation date and I've created token only few days back. So I don't know the output. Right now, it is generating xml response with error message.

Now this method is returning me a single string which seems to be the Access Token. Do I also need to renew Access Token Secret ? If yes, then how to generate it ? Or the output contains secret as well ?

Actually, Can you give me the output for this method?

@sanjayapandey
Copy link

Can you please provide us the Java sample code for reconnect? We are stuck on it badly.

@obryanlouis
Copy link

You can test with a shorter period by going here: https://appcenter.intuit.com/Playground/OAuth/IA/.

The possible responses are here: https://developer.intuit.com/docs/0025_quickbooksapi/0053_auth_auth/oauth_management_api#Reconnect.

For example, a successful response would look like:

<ReconnectResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://platform.intuit.com/api/v1">    
    <ErrorMessage/>    
    <ErrorCode>0</ErrorCode>    
    <ServerTime>2012-01-04T19:21:21.0782072Z</ServerTime>    
    <OAuthToken>qye2eIdQ5H5yMyrlJflUWh712xfFXjyNnW1MfbC0rz04TfCP</OAuthToken>    
    <OAuthTokenSecret>cyDeUNQTkFzoR0KkDn7viN6uLQxWTobeEUKW7I79</OAuthTokenSecret>
</ReconnectResponse>

@DureSameen
Copy link

Why am I getting this response. Please help

   <?xml version="1.0" encoding="utf-8"?>
     <ReconnectResponse xmlns:xsd="http://www.w3.org/2001/XMLSchema"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://platform.intuit.com/api/v1">
   <ErrorMessage>OAuth Token rejected</ErrorMessage>
    <ErrorCode>270</ErrorCode>
   <ServerTime>2015-04-01T10:41:11.5739677Z</ServerTime>
</ReconnectResponse>

@daking1
Copy link

daking1 commented Oct 2, 2015

@DureSameen:
This error occurs when you are trying to renew an invalid access token. This can happen if someone disconnected from QuickBooks or if it is already expired. You can only quietly renew an access token in the background before it expires but only if it will expired within the next 30 days. If you get this, that means the user needs to reconnect/authorize your app to get a new access token.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment