eBay / ebay-oauth-csharp-client

eBay OAuth C# Client Library
Apache License 2.0
56 stars 42 forks source link

Authorization Code Grant Flow Does Not Work #40

Open 900008676 opened 8 months ago

900008676 commented 8 months ago

I followed the instructions listed in the readme. I confirmed authorization URL is correct and matched what I see in the API Explorer. I am able to get a user token using the User Tokens section of eBay Developers website. However, the SDK is returning, "invalid_grant...the provided authorization grant code is invalid or was issue to another client". Here is the C# .NET 8 console application code. What am I doing wrong or it there a bug?

using eBay.ApiClient.Auth.OAuth2;
using eBay.ApiClient.Auth.OAuth2.Model;

CredentialUtil.Load("ebay-config.yaml");

OAuth2Api ebayApi = new OAuth2Api();

string userAuthorizationUrl = ebayApi.GenerateUserAuthorizationUrl(OAuthEnvironment.PRODUCTION, new List<string>()
{
    "https://api.ebay.com/oauth/api_scope/sell.fulfillment.readonly"
}, null);

if (!string.IsNullOrEmpty(userAuthorizationUrl))
{
    Console.WriteLine($"Authorization Url: {userAuthorizationUrl}");
    OAuthResponse response = ebayApi.ExchangeCodeForAccessToken(OAuthEnvironment.PRODUCTION, userAuthorizationUrl);
    if (response != null && response?.AccessToken == null)
    {
        Console.WriteLine($"Error Getting Token: {response?.ErrorMessage}");
    }
    else
    {
        Console.WriteLine($"Access Token: {response?.AccessToken}");
    }
}
else
{
    Console.WriteLine("Failed to get authorization URL");
}
yunits commented 7 months ago

Without reviewing your code: I guess it is not compatible with .NET 8. Did you try to downgrade to .NET 6 for testing purposes? Otherwise just download and copy classes into your project until this repo gets updated.