0

Error from Xero :

Token does not match an expected REQUEST token

The issue seems to be related to the comment from the Xero help site?

This error will also occur if the session handle is not used in the access token renewal process.

I have confirmed I do not get this on the return object of the following :

 public async Task<AccessTokenDto> Authorise(string oauth_token, string oauth_verifier, string org)
 {
             var xeroacessToken = 
                       _authenticator.RetrieveAndStoreAccessToken(_user.Name, 
             oauth_token, oauth_verifier, org);
 }

I am not sure how I get the session handle and then how to use this in my service call to renew the token? As per the example I was expecting this on my token.

oauth_session_handle=ODJHMGEZNGVKMGM1NDA1NZG3ZWIWNJ "Session Handle used to renew the access token"

Code that works the first time with the token that has been retrieved from the database:

        var tokenStore = new MemoryTokenStore();
        tokenStore.Add(xerotoken);

        var api = new RA.Xero.Partner.Core(tokenStore, XeroUser(UserId)), _hostingEnvironment)
        {
            UserAgent = "My Partner App " + input.ConsumerKey,

        };

I tried to see if using the Partner Authentication directly would work :

        var tokenStore = new MemoryTokenStore();
        tokenStore.Add(xerotoken);
        Settings ApplicationSettings = new Settings();

        X509Certificate2 certificate = RA.Xero.Partner.Core.Certificate(_hostingEnvironment);

        var partnerAuthentication = new RA.Xero.Public.PartnerAuthenticator(
                ApplicationSettings.Uri,
                ApplicationSettings.AuthorizeUri,
                ApplicationSettings.CallBackUri,
                tokenStore,
                certificate
               );

        var consumer = new Consumer(ApplicationSettings.Key, 
         ApplicationSettings.Secret);
        var token = partnerAuthentication.GetToken(consumer, 
         XeroUser(UserId));

I have checked the keys are the partner keys in my app and any hints or sample code would be great.

Mr Bird
  • 1
  • 1
  • Are you using one of the Xero-created SDKs? There are useful examples on Github in the two .NET repos - https://github.com/XeroAPI/Xero-NetStandard and https://github.com/XeroAPI/Xero-Net – rustyskates Sep 10 '18 at 21:02
  • Yes, the code from above is from the examples. Also we had the Public app working with the examples fine. It's only from switching over to use the Partner app that I cannot understand/seem to get the Session Handle. – Mr Bird Sep 10 '18 at 23:33

0 Answers0