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

Refresh Token - From where to get eBay Refresh Token

I want to get an access token in C# API for that I will need a refresh token, from where I can get it.

salsha7566_0-1678780110026.png

 

 

Message 1 of 3
latest reply
2 REPLIES 2

Refresh Token - From where to get eBay Refresh Token

A couple of posts that might help:

 

https://community.ebay.com/t5/RESTful-Sell-APIs-Fulfillment/c-eBay-Utility-going-round-in-circles-tr...

 

https://community.ebay.com/t5/RESTful-Sell-APIs-Fulfillment/the-provided-authorization-grant-code-is...

 

In addition, the response from shipscript on the other post shows the implementation in php.

 

Also, don't post any tokens, or credentials you've encoded to the forums, that is a security issue...

 

So like is mentioned in each of those posts, you do not want the client_credentials grant type you are using, that gives an application token, you want a user token.

 

The user token is a 2 step process

 

What you want is to generate a URL first.

 

Use that url to log in.

 

When you log in the URL will update to a string that contains a code= &

 

Grab that, make a body that uses the grant type of authorization_code with just:

 

"grant_type": "authorization_code"
"redirect_uri": YOUR_REDIRECT_URI_HERE
"code": THE_AUTHORIZATION_CODE_YOU_GOT_FROM_RETURNED_URL_PARAM

 

This will return the refresh token and the access token.

 

You can then use:

 

"grant_type": "refresh_token"
"refresh_token": THE_REFRESH_USER_TOKEN_YOU_GOT
"scope": "your scopes separated by spaces"

 

on that refresh token from that point forward.

 

 

A rough example of the 1st half:

  static string appId = "";
  static string certId = "";
  static string redirectUri = "";
  static string scopeListString = "https://api.ebay.com/oauth/api_scope https://api.ebay.com/oauth/api_scope/sell.inventory https://api.ebay.com/oauth/api_scope/sell.marketing https://api.ebay.com/oauth/api_scope/sell.account https://api.ebay.com/oauth/api_scope/sell.fulfillment";
  static string oauthsignin = "https://auth.ebay.com/oauth2/authorize";
  static string oauthendpoint = "https://api.ebay.com/identity/v1/oauth2/token";
  static string Generate_Url()
  {
    Guid uuid4 = Guid.NewGuid();
    NameValueCollection qs = HttpUtility.ParseQueryString("");
    qs.Add("client_id", appId);
    qs.Add("redirect_uri", redirectUri);
    qs.Add("response_type", "code");
    qs.Add("prompt", "login");
    qs.Add("scope", scopeListString);

    //include or not, this works either way, but it might not be useful or implemented incorrectly
    //oauth2 standards documentation is lacking and vague on how to implement correctly
    qs.Add("state", uuid4.ToString());

    return oauthsignin + "?" + qs;
  }

  Console.WriteLine("\nEnter the following URL into a browser and log in, grab param between code= and & once logged in:\n");
  Console.WriteLine(Generate_Url() + "\n");
  Console.WriteLine("Enter in the code= param you copied from the returned URL");
  string codeinput = Console.ReadLine();

  string body = $"grant_type=authorization_code&redirect_uri={redirectUri}&code={codeinput}"
  response = client.UploadString(oauthendpoint, body);
  json = JObject.Parse(response);
  Console.WriteLine("This is the token response:\n");
  Console.WriteLine(json.ToString());

 

Message 2 of 3
latest reply

Refresh Token - From where to get eBay Refresh Token

@five_notch_trading_post Thanks for the help and Suggestions. It is working now.

 

Message 3 of 3
latest reply