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

the provided authorization grant code is invalid or was issued to another client

I'm getting this error when trying to use OAUTH, i've checked and my key is in the right  format i.e it does not start with "code="

 

{"error":"invalid_grant","error_description":"the provided authorization grant code is invalid or was issued to another client"}

the token from get_token looks like this

v^1.1#i^1#f^0#p^1#r^0#I^3#t^H4sIAAAAAAA.......................

 

Any help is much appreciated!

 

import EbayAuthToken from 'ebay-oauth-nodejs-client';


const line = "---------------------------------------------------------------------------------------------------";
const seperator = `\n${line}\n`

const ebayAuthToken = new EbayAuthToken({
    clientId: 'xxxxxxx',
    clientSecret: 'xxxxxx'
});

const scopes ={ scopes: [
]};

async function get_token(){

  //Get token object (we will receive it as a string so we have to convert it)
  const token = await ebayAuthToken.getApplicationToken('PRODUCTION', scopes);
  //convert to json
  const token_object = JSON.parse(token);

  console.log(seperator+`Authorization code`+seperator+token_object.access_token+seperator);
 
  exchange_authorization_code_for_access_token(token_object.access_token);
}

async function exchange_authorization_code_for_access_token(code){
  const accessToken = await ebayAuthToken.exchangeCodeForAccessToken('PRODUCTION', code);
  console.log(accessToken);
}



get_token();
 
 
Message 1 of 3
latest reply
1 BEST ANSWER

Accepted Solutions

the provided authorization grant code is invalid or was issued to another client

ebayAuthToken.getApplicationToken is for obtaining an Application token. Which is a separate thing from a user token.

 

What you are looking for is ebayAuthToken.generateUserAuthorizationUrl(environment, scopes[, options])

You then load the resulting URL in a browser, log in, and once you are logged in, the URL in the browser will then have a code= in it. You grab the stuff between the code= & and submit that to exchange_authorization_code_for_access_token, which will then result in the User access token

 

It will also return a refresh token along with it, which you can then use

ebayAuthToken.getAccessToken(environment, refreshToken, scopes)

to refresh the access token without logging back in.

View Best Answer in original post

Message 2 of 3
latest reply
2 REPLIES 2

the provided authorization grant code is invalid or was issued to another client

ebayAuthToken.getApplicationToken is for obtaining an Application token. Which is a separate thing from a user token.

 

What you are looking for is ebayAuthToken.generateUserAuthorizationUrl(environment, scopes[, options])

You then load the resulting URL in a browser, log in, and once you are logged in, the URL in the browser will then have a code= in it. You grab the stuff between the code= & and submit that to exchange_authorization_code_for_access_token, which will then result in the User access token

 

It will also return a refresh token along with it, which you can then use

ebayAuthToken.getAccessToken(environment, refreshToken, scopes)

to refresh the access token without logging back in.

Message 2 of 3
latest reply

the provided authorization grant code is invalid or was issued to another client

Thank you so much for your reply!

It cleared up a lot of confusion regarding the different tokens. In my opinion the documentation is extremely lacking and confusing. I study engeering in this field and I do way more complicated things daily but its's very hard with the lacking documentation.

Message 3 of 3
latest reply