Xero - beautiful accounting software

Xero Developer Help Center

Xero Developer Community

Community > API Authentication >

How can I read the verification code from request token?

Started by Mark Lazarus -   in API Authentication

I have registered a partner application with XERO and need to get the verification code so that user does not need to authorize manually. I have set the callback url as well but could not find a way to read verification code automatically. MVC sample code is not of much use for me.I have to exchange request token with access token where the 401 error is generating.
My code is

public void GetRequestToken(string PCK, string PCS)
{
try
{
OAuthConsumerContext consumerContext = new OAuthConsumerContext
{
ConsumerKey = PCK,
ConsumerSecret = PCS,
SignatureMethod = SignatureMethod.RsaSha1,
UseHeaderForOAuthParameters = true,
UserAgent = PartnerUserAgentString,
Key = OAuthSigningCertificate.PrivateKey

};
OAuthSession consumerSession = new OAuthSession(
consumerContext,
PartnerRequestTokenURI,
AuthoriseURI,
PartnerAccessTokenURI,"http://localhost:4818/QSS_A_Main/Home.aspx");

consumerSession.ConsumerRequestFactory = new ClientCertEnabledConsumerRequestFactory(ClientSslCertificateFactory);
IToken requestToken = consumerSession.GetRequestToken();


TokenBase accessToken;
accessToken = (TokenBase)consumerSession.ExchangeRequestTokenForAccessToken(requestToken);// error generates here

}
catch (Exception ex)
{
// throw new ApplicationException("The request token could not be obtained from the Xero API server", ex);

}
If you have specified a callback url then it will be returned in the callback url as query string parameter when it is redirected back by XERO to that url.
 

Sushant Kumar