PHPackages                             dvicklund/ebay-oauth-php-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. dvicklund/ebay-oauth-php-client

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

dvicklund/ebay-oauth-php-client
===============================

Enables the simple retreival of an eBay API OAuth token

1.2(2y ago)38.5k↓36.6%2Apache-2.0PHPPHP &gt;=7.4

Since Jun 12Pushed 2y ago1 watchersCompare

[ Source](https://github.com/dvicklund/ebay-oauth-php-client)[ Packagist](https://packagist.org/packages/dvicklund/ebay-oauth-php-client)[ RSS](/packages/dvicklund-ebay-oauth-php-client/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (3)Dependencies (1)Versions (5)Used By (0)

Ebay Oauth Client
=================

[](#ebay-oauth-client)

[![Code coverage badge](https://github.com/dvicklund/ebay-oauth-php-client/raw/image-data/coverage.svg)](https://github.com/dvicklund/ebay-oauth-php-client/blob/image-data/coverage.svg)

Allows developers to fetch an OAuth token that can be used to call the eBay Developer REST APIs using PHP.

What is OAuth
-------------

[](#what-is-oauth)

OAuth 2.0 is the most widely used standard for authentication and authorization for API based access. The complete end to end documentation on how eBay OAuth functions may be used is available at developer.ebay.com. See:

Installation
------------

[](#installation)

Include in your project via composer:

```
$ composer require dvicklund/ebay-oauth-php-client
```

Usage
-----

[](#usage)

##### EbayAuthToken(config)

[](#ebayauthtokenconfig)

Create a new instance of `EbayAuthToken` with a relevant config.

```
use EbayOauthToken\EbayOauthToken;

$ebayAuthToken = new EbayOauthToken([
    'env' => '', // If not provided, env defaults to PRODUCTION
    'clientId' => '',
    'clientSecret' => '',
    'redirectUri' => ''
]);
```

##### $ebayAuthToken-&gt;getApplicationToken(environment)

[](#ebayauthtoken-getapplicationtokenenvironment)

Generate client credential token.

```
$token = $ebayAuthToken->getApplicationToken('PRODUCTION');
print($token);
```

##### $ebayAuthToken-&gt;generateUserAuthorizationUrl(environment, scopes\[, options\])

[](#ebayauthtoken-generateuserauthorizationurlenvironment-scopes-options)

Generate user consent authorization url.

```
$authUrl = $ebayAuthToken->generateUserAuthorizationUrl('PRODUCTION', $scopes);
print($authUrl);
```

You can also provide optional values:
**state:** An opaque value used by the client to maintain state between the request and callback.
**prompt:** Force a user to log in when you redirect them to the Grant Application Access page, even if they already have an existing user session.

The method call above could also be done as

```
$options = [ 'state' => 'custom-state-value', 'prompt' => 'login' ];
$authUrl = $ebayAuthToken->generateUserAuthorizationUrl('PRODUCTION', $scopes, $options);
print($authUrl);
```

##### $ebayAuthToken-&gt;exchangeCodeForAccessToken(environment, code)

[](#ebayauthtoken-exchangecodeforaccesstokenenvironment-code)

Get a User access token.

```
$accessToken = $ebayAuthToken->exchangeCodeForAccessToken('PRODUCTION', $code);
print($accessToken);
```

##### $ebayAuthToken-&gt;getAccessToken(environment, refreshToken, scopes)

[](#ebayauthtoken-getaccesstokenenvironment-refreshtoken-scopes)

Use a refresh token to update a User access token (Updating the expired access token).

```
$accessToken = $ebayAuthToken->getAccessToken('PRODUCTION', $refreshToken, $scopes);
print($accessToken);
```

Library Setup and getting started
---------------------------------

[](#library-setup-and-getting-started)

1. Invoke the oauth ebay library as given below

```
use EbayOauthToken\EbayOauthToken;

$ebayAuthToken = new EbayOauthToken([
    'filePath' => 'demo/eBayJson.json' // input file path.
]);
```

OR

```
$ebayAuthToken = new EbayOauthToken([
    'clientId' => '',
    'clientSecret' => '',
    'redirectUri' => ''
]);
```

2. If you want to get your application credentials such as AppId, DevId, and CertId. Refer to [Creating eBay Developer Account](https://developer.ebay.com/api-docs/static/creating-edp-account.html) for details on how to get these credentials.
3. You can refer to Example.php for an example of how to use credentials.
4. For Authorization code grant
    1. Get user consent url using `$ebayAuthToken->generateUserAuthorizationUrl()`
    2. Open the generateUserAuthorizationUrl in the browser, which allows you to login in to ebay site. You will get an authorization code.
    3. Pass the authorization code retrieved in the above step to exchangeCodeForAccessToken method using `$ebayAuthToken->exchangeCodeForAccessToken($environment, $code)`

Configure credentials
---------------------

[](#configure-credentials)

Create a config JSON file in your application. The config file should contain your eBay applications keys: App Id, Cert Id &amp; Dev Id. A sample config file is available at demo/ebay-config-sample.json. You could also set these parameters in a .env file, and pass them into the `$options` object during setup.

```
{
    "SANDBOX": {
        "clientId": "---Client Id---",
        "clientSecret": "--- client secret---",
        "devid": "-- dev id ---",
        "redirectUri": "-- redirect uri ---",
        "baseUrl": "api.sandbox.ebay.com" //don't change these values
    },
    "PRODUCTION": {
        "clientId": "---Client Id---",
        "clientSecret": "--- client secret---",
        "devid": "-- dev id ---",
        "redirectUri": "-- redirect uri ---",
        "baseUrl": "api.ebay.com" //don't change these values
    }
}
```

Types of Tokens
---------------

[](#types-of-tokens)

There are two types of tokens you will need to use.

### Application Token

[](#application-token)

An application token contains an application identity which is generated using client\_credentials grant type. These application tokens are useful for interaction with application specific APIs such as usage statistics, etc.

### User Token

[](#user-token)

A user token (access token or refresh token) contains a user identity and the application’s identity. This is usually generated using the authorization\_code grant type or the refresh\_token grant type.

Supported Grant Types for OAuth
-------------------------------

[](#supported-grant-types-for-oauth)

All of the regular OAuth 2.0 specifications such as client\_credentials, authorization\_code, and refresh\_token are supported. [Refer to eBay Developer Portal](https://developer.ebay.com/api-docs/static/oauth-tokens.html)

### Client Credentials

[](#client-credentials)

This grant type can be performed by simply using `$ebayAuthToken->getApplicationToken()`. Read more about this grant type at [oauth-client-credentials-grant](https://developer.ebay.com/api-docs/static/oauth-client-credentials-grant.html).

### Authorization Code

[](#authorization-code)

This grant type can be performed by a two step process. Call `$ebayAuthToken->generateUserAuthorizationUrl($environment, $scopes, $state)` 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 and then call `$ebayAuthToken->exchangeCodeForAccessToken($environment, $code)` to get the refresh and access tokens.

Read more about this grant type at [oauth-authorization-code-grant](https://developer.ebay.com/api-docs/static/oauth-authorization-code-grant.html).

### Refresh Token

[](#refresh-token)

This grant type can be performed by simply using `$ebayAuthToken->getAccessToken($environment, $refreshToken, $scopes)`. Usually, access tokens are short lived. If the access token is expired, the caller can use the refresh token to generate a new access token. Read more about [using a refresh token to update a user access token](https://developer.ebay.com/api-docs/static/oauth-auth-code-grant-request.html)

Questions/problems?
-------------------

[](#questionsproblems)

If you have found a bug/issue, please file it on [GitHub](https://github.com/dvicklund/ebay-oauth-php-client/issues).

References
----------

[](#references)

1.
2.
3.
4.

License
-------

[](#license)

Copyright (c) 2023 David Vicklund.

Use of this source code is governed by an Apache-2.0 license that can be found in the LICENSE file or at .

Useful links
------------

[](#useful-links)

- Getting Client Id and Client Secret:
- Getting your redirect\_uri value:
- Specifying right scopes:

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~23 days

Total

3

Last Release

1072d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d751c7d33e73329ae34248ace685ba4d3a167787bf1d4115291b1ed8ef5c0aae?d=identicon)[dvicklund](/maintainers/dvicklund)

---

Top Contributors

[![dvicklund](https://avatars.githubusercontent.com/u/1349656?v=4)](https://github.com/dvicklund "dvicklund (70 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dvicklund-ebay-oauth-php-client/health.svg)

```
[![Health](https://phpackages.com/badges/dvicklund-ebay-oauth-php-client/health.svg)](https://phpackages.com/packages/dvicklund-ebay-oauth-php-client)
```

###  Alternatives

[kartik-v/yii2-password

Useful password strength validation utilities for Yii Framework 2.0

761.3M17](/packages/kartik-v-yii2-password)[vitalybaev/laravel5-dkim

Laravel 5/6 package for signing outgoing messages with DKIM.

3163.1k](/packages/vitalybaev-laravel5-dkim)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
