Giter Site home page Giter Site logo

ebay-oauth-csharp-client's Introduction

Summary

To make integrations with eBay RESTful APIs easier, eBay provides client libraries in C# and Java to make it simpler to set up authorization, reduce the amount of code the application developers have to write to get OAuth Access Tokens. This library in addition to functioning as a simple eBay OAuth Client, helps with additional features such as cached App tokens.

What is OAuth 2.0

OAuth 2.0 is the industry-standard protocol for authorization to obtain limited access to an HTTP service. All eBay RESTful APIs use the OAuth 2.0 protocol for authorization. OAuth access tokens verify to eBay that a request is coming from a valid client and that the application has the user’s authorization to carry out the requests. Learn more about the OAuth Access Tokens.

Supported Languages

eBay OAuth Client is a class library that targets the .NET Standard 2.0. This library can be used by any .NET implementation that supports 2.0 version of the .NET Standard.

Add the eBay.OAuth.Client NuGet Package

Current Version : 2.0.2

Use of this source code is governed by Apache-2.0 license.If you’re looking for the latest stable version (2.0.2), you can grab it directly from NuGet.org.

https://www.nuget.org/packages/eBay.OAuth.Client

NuGet Package Manager UI

  • In Solution Explorer, right-click NuGet in .csproj and choose Add Package.

  • Search for eBay.OAuth.Client, select that package in the list, and click on Add Package

  • Accept the License prompt

Package Manager Console

  • Use the following command in your project directory, to install the eBay.OAuth.Client package:
Install-Package eBay.OAuth.Client -Version 2.0.2
  • After the command completes, open the .csproj file to see the added reference:
<ItemGroup>
   <PackageReference Include="eBay.OAuth.Client" Version="2.0.2" />
</ItemGroup>

.NET CLI

  • Use the following command in your project directory, to install the eBay.OAuth.Client package:
dotnet add package eBay.OAuth.Client --version 2.0.2
  • After the command completes, open the .csproj file to see the added reference:
<ItemGroup>
   <PackageReference Include="eBay.OAuth.Client" Version="2.0.2" />
</ItemGroup>

Paket CLI

  • Use the following command in your project directory, to install the eBay.OAuth.Client package:
paket add eBay.OAuth.Client --version 2.0.2
  • After the command completes, open the .csproj file to see the added reference:
<ItemGroup>
   <PackageReference Include="eBay.OAuth.Client" Version="2.0.2" />
</ItemGroup>

Build eBay.OAuth.Client DLL from Source

  • After cloning the project, you can build the package from the source by executing following script from project directory:
  • ebay-oauth-csharp-client.dll will be created at ebay-oauth-csharp-client/bin/Debug/net6.0

Use the eBay.OAuth.Client in the .NET App

name: ebay-config
api.sandbox.ebay.com:
    appid: <appid-from-developer-portal>
    certid: <certid-from-developer-portal>
    devid: <devid-from-developer-portal>
    redirecturi: <redirect_uri-from-developer-portal>
Api.ebay.com:
    appid: <appid-from-developer-portal>
    certid: <certid-from-developer-portal>
    devid: <devid-from-developer-portal>
    redirecturi: <redirect_uri-from-developer-portal>
  • Once the config file is ready, use following code to load it. It is recommended to load the credentials during startup time (initialization) to prevent runtime delays.
CredentialUtil.Load(“YAML config file path”);
or
CredentialUtil.Load(System.IO.StreamReader);
  • Once the credentials are loaded, call any operation on OAuth2Api.

    1. GetApplicationToken: Use this operation when the application request an access token to access their own resources, not on behalf of a user. Learn more about Client Credentials grant flow.
OAuth2Api.GetApplicationToken(OAuthEnvironment environment, IList<String> scopes)
  1. GenerateUserAuthorizationUrl: Use this operation to get the Authorization URL to redirect the user to. Once the user authenticates and approves the consent, the callback needs to be captured by the redirect URL setup by the app.
OAuth2Api.GenerateUserAuthorizationUrl(OAuthEnvironment environment, IList<String> scopes, String state)
  1. ExchangeCodeForAccessToken: Use this operation when an application exchanges an authorization code for an access token. After the user authenticates, approves the consent and returns to the application via the redirect URL , the application will get the authorization code from the URL and use it to request an access token. Learn more about Authorization Code grant flow.
OAuth2Api.ExchangeCodeForAccessToken(OAuthEnvironment environment, String code)
  1. GetAccessToken: Usually access tokens are short lived. Use this operation to update the access token. Learn more about Using a refresh token to update the access token.
OAuth2Api.GetAccessToken(OAuthEnvironment environment, String refreshToken, IList<String> scopes)

Contribution

Contributions in terms of patches, features, or comments are always welcome. Refer to CONTRIBUTING for guidelines. Submit Github issues for any feature enhancements, bugs, or documentation problems as well as questions and comments.

License

Copyright (c) 2018-2019 eBay Inc.

Use of this source code is governed by a Apache 2.0 license that can be found in the LICENSE file or at https://opensource.org/licenses/Apache-2.0.

ebay-oauth-csharp-client's People

Contributors

lokeshrishi avatar sdhiman30 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ebay-oauth-csharp-client's Issues

Version 2.* has no namespace

the using directives doesn't work in Version 2.*

using eBay.ApiClient.Auth.OAuth2;

I can't use any function, because type and namespaces are not found.
(Using C#, VS 2022, Console App, .Net 7.0)

.NETFramework Version v4.8 issue

Hello,

i can not install the package. The following error Code i got:

Install-Package : Could not install package 'eBay.OAuth.Client 1.0.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.8', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

Thank for your help.

The requested scope is invalid

Hi there,
I get this error when I cloned and changed the info with my ClientId/Secret Key etc.

The error is: ""{"error":"invalid_scope","error_description":"The requested scope is invalid, unknown, malformed, or exceeds the scope granted to the client"}"

The scopes I supply are only and I definitely have access to these scopes:
https://api.ebay.com/oauth/api_scope, https://api.ebay.com/oauth/api_scope/sell.fulfillment

If I try only https://api.ebay.com/oauth/api_scope then it works and returns an access token. Which means my configurations are correct.

What is this error and why this should happen?

I have access to all these scopes. See below:

image

TIA

Targeting multiple frameworks

Why not target both .net standard and .net 6.0 (see PR #31).

This way this handy library can still be used on projects still using .net framework?

What do you think?

Feature Request: JSON Support

In addition to natively taking in and parsing a YAML file, with .NET Core promoting use of files such as appsettings.json, it would be incredibly useful for this library to support JSON out of the box. This could be done via StreamReader, but having support like with YAML would follow the paradigm Microsoft has set.

bypassing .yaml file when building OAuth integration

Hi,

We were looking for an alternative when it comes to setting a .yaml file for storing our ebay credentials when using the ebay Oauth client.

String path = @"../../../ebay-config-sample.yaml";

production-user: username: <production-username> password: <production-user-password>

is there any way to insert it as an object, instead of a text file / yaml when calling CreateAuthorizationHeader_Success method?

AppTokenCache Dictionary Update Error

I'm using the following code to retrieve an Oauth token:

var oauth = new OAuth2Api();

CredentialUtil.Load(sr);

var scopes = new[]
{
    WebUtility.UrlEncode("https://api.ebay.com/oauth/api_scope"),
    WebUtility.UrlEncode("https://api.ebay.com/oauth/api_scope/buy.marketplace.insights")
};

var response = oauth.GetApplicationToken(OAuthEnvironment.PRODUCTION, scopes);

And I'm getting the following error (with the stacktrace):

System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add) at System.Collections.Generic.Dictionary2.Add(TKey key, TValue value)
at eBay.ApiClient.Auth.OAuth2.OAuth2Api.AppTokenCache.UpdateValue(OAuthEnvironment environment, OAuthResponse oAuthResponse, DateTime expiresAt)
at eBay.ApiClient.Auth.OAuth2.OAuth2Api.GetApplicationToken(OAuthEnvironment environment, IList`1 scopes)

Should there be a check here to see if the key exists first, before adding?:
https://github.com/eBay/ebay-oauth-csharp-client/blob/master/ebay-oauth-csharp-client/eBay/ApiClient/Auth/OAuth2/OAuth2Api.cs#L50

Grant authorization code not generate

image

Selenium.Chrome.WebDriver is incompatible with the latest Chrome version which is 126.0,
Due to driver and Chrome version incompatibility, the code cannot open a browser and throws an exception.
IWebDriver driver = new ChromeDriver(Directory.GetCurrentDirectory());

All your suggestion and resolution would be much appriciate

Support for reading Credentials for CredentialUtil from DbProvider

Hi,

Would it be possible to add functionality the the CredentialsUtil class to allow injection of a service to read the Credentials from database provider?

The use case here is for myself a webapplication where the Credentials will be stored and managed within the database via the web interface. i would like it as so if the Credentials need to be updated that a ConfigFile/App restart is not required, thus it makes sense to have either the CredentialsUtil or Oauth2API to use a service to retrieve the details from the database when required...

Errror FileLoadException RestSharp

I am load GetApplicationToken
CredentialUtil.Load(path);
IList<string> list = new List<string>() { "https://api.ebay.com/oauth/api_scope" };
OAuthResponse oAuthResponse = new OAuth2Api().GetApplicationToken(eBay.ApiClient.Auth.OAuth2.Model.OAuthEnvironment.SANDBOX, list);
but a get next error
System.IO.FileLoadException: 'Could not load file or assembly 'RestSharp, Version=106.5.4.0, Culture=neutral, PublicKeyToken=598062e77f915f75'. Could not find or load a specific file. (0x80131621)'
in my csproj i add <PackageReference Include="RestSharp" Version="106.5.4" />

Has anyone ever experienced this? can you help me

Out of date dependencies

Hello,

Would the maintainers be open to accept a pull request that updating the dependencies of this project? I'd be happy to submit one.

Proposed change:

diff --git a/ebay-oauth-csharp-client/ebay-oauth-csharp-client.csproj b/ebay-oauth-csharp-client/ebay-oauth-csharp-client.csproj
index 74ed47f..fd6a976 100644
--- a/ebay-oauth-csharp-client/ebay-oauth-csharp-client.csproj
+++ b/ebay-oauth-csharp-client/ebay-oauth-csharp-client.csproj
@@ -4,12 +4,9 @@
     <RootNamespace>eBay.ApiClient.Auth.oAuth2</RootNamespace>
   </PropertyGroup>
   <ItemGroup>
-    <Folder Include="eBay\ApiClient\Auth\" />
-  </ItemGroup>
-  <ItemGroup>
-    <PackageReference Include="YamlDotNet" Version="5.3.0" />
-    <PackageReference Include="RestSharp" Version="106.5.4" />
-    <PackageReference Include="log4net" Version="2.0.8" />
-    <PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
+    <PackageReference Include="YamlDotNet" Version="13.1.0" />
+    <PackageReference Include="RestSharp" Version="108.0.2" />
+    <PackageReference Include="log4net" Version="2.0.15" />
+    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
   </ItemGroup>
 </Project>

The main driver for this is that YamlDotNet is very out of date and the current nuget package referenced doesn't has its publicKeyToken assembly property to set and this is causing FileNotFound exceptions if you happen to also reference a more recent version of the package (that will have a publicKeyTokenVaue.

The referenced version of Newtonsoft.Json and log4net have some known vulnerabilities.

The other updates are just general housekeeping.

Unit Test Issues

I used the unit tests to verify that I had my eBay developer account set up correctly, and I found several issues with the unit tests.

  1. For the GetAccessToken_EndToEnd_Production and GetAccessToken_EndToEnd_Sandbox tests the sign in page no longer has element id's of userid and pass, instead they are numeric and change for each visit to the sign in form. I didn't look at changing the logic to find the correct fields, I debugged the test case and manually gave access.

  2. At least for my eBay developer account the values in the scopes list were only valid for the sandbox so GetAccessToken_EndToEnd_Production would fail with an invalid scope error.

  3. XUnit no longer writes to the console. Instead it takes a ITestOutputHelper as an argument to the test constructor and saves the references. Then it uses that reference to log. The log results are available in the Test Detail Summary for each test.

.NET 7 and .NET 8 support

As .NET 8 has been released it would be nice to support at least .NET 7.
I already use a forked version with .NET 7 without any issues.

Aysnc Support

Hi, I am discovering this library in July 2020.

I have noticed there are Async operations for the calls to the API.

Is there a reason for this?

eBay US Oauth access Token generating successfully but for eBay CA its throwing Invalid Scope error

After RestSharp v107 the IRestResponse interface is deprecated

Hi

With RestSharp v108 i have this exception
System.TypeLoadException : 'Impossible de charger le type 'RestSharp.IRestResponse' à partir de l'assembly 'RestSharp, Version=108.0.1.0

Documentation : The IRestResponse interface is deprecated. You get an instance of RestResponse or RestResponse in return.

So interface with RestSharp must be updated.

Best regards

System.IO.FileLoadException / Exception Unhandled

Good morning. I have been struggling with an issue for several weeks. I am going to preface this by saying, I am relatively new to .NET. I am trying to load a YAML config file at form load on a .NET Windows Forms application. I am using CredentialUtil.Load with my file path to the YAML file. I am getting the following exception, and I was hoping you may be able to help guide me through it. I have looked high and low for a good answer, but I haven't found one yet. I installed YamlDotNet through NuGet Package Manager in Visual Studio 2019, and the current version is 8.0.0. I have eBay.Oauth.Client v1.0.1 installed, as well.

image

(Text: System.IO.FileLoadException: 'Could not load file or assembly 'YamlDotNet, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)')

Invalid config

Hi,

Just want to point out you have a typo in README.md

Api.ebay.com:
appid:
certid:
devid:
redirecturi: <redirect_uri-from-developer-portal>

should be api.ebay.com (case sensitive)

Invalid Client_id error

Hi,
I am having issue callling
OAuthResponse oAuthResponse = oAuth2Api.GetApplicationToken(OAuthEnvironment.SANDBOX, scopes);
it returns an error "Invalid client_id" but its working fine with Postman.

Authorization Code Grant Flow Does Not Work

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");
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.