Code Monkey home page Code Monkey logo

ebay_oauth_php_example's Introduction

eBay_OAuth_PHP_example

Grant User Access & Refresh Tokens, refreshes User tokens.

This is an example in PHP of how to follow the authorization grant flow. It directs the user to the eBay consent page and grants them a consent token which is then exchanged for the User Access Token and Refresh Token. Also included is an example of how to refresh the User Access Token.

The index.php file in the root directory will redirect the user to the eBay consent form. If they're not logged into eBay, they will be prompted to login. If/when they are logged in, eBay will display the list of permissions this application has defined in its scope. If they agree, eBay will send the Consent Token to /success/index.php which will capture it. The Consent Token is then automatically exchanged for a User Access Token and Refresh Token.

At the time of this writing, the Refresh Token is valid for 18 months and the User Access Token is valid for 2 hours. Therefore, in your application you will need to check when the User Access Token was granted, and if it has expired, then you will need to use the Refresh Token to generate a new User Access Token.

All received tokens will be located in ./tokens/

Requirements: developer account from https://developer.ebay.com/ create an application key https://developer.ebay.com/my/keys

On the Application Keys page (https://developer.ebay.com/my/keys) click User Tokens under your application. Scroll down the page to "Your eBay Sign-in Settings" and look for "Your auth accepted URL1". Set this field to the URL on your server where the /success/ folder is (do not include index.php in the URL). For example: https://example.org/ebay-oauth-example/success/

From this same section, copy the "RuName (eBay Redirect URL name)". Go back to the Application Keys page, copy your App ID and Cert ID credentials.

Place these credentials into each PHP script in this example (both index.php files and refresh_token.php).

To use this example, you will never access /success/index.php directly. Instead, you will access the main index.php file. For example: https://example.org/ebay-oauth-example/ This is the page which will bring you to the eBay consent page.

Once the user has consented, eBay will redirect to the /success/ URL which will capture the Consent Token, then exchange this token for the Refresh Token and User Access Token. The resulting tokens will be printed on the page and deposited in ./tokens/UserAccessToken.json

To refresh the User Access Token, run refresh_token.php. The refresh token will be deposited in ./tokens/RefreshToken.json

Note that this example is a basic implementation and does not refresh tokens automatically. You will need to add additional logic, error handling and security. Always store your credentials outside of the web root or in a database, never hard-code them or store the received tokens in flat files in the web root. It is a security risk.

Additional info: https://developer.ebay.com/api-docs/static/oauth-consent-request.html https://developer.ebay.com/api-docs/static/oauth-auth-code-grant-request.html

Warning: do not store any credentials in code or in your web root. This example is just for demonstration purposes only and is not authorized by eBay.

ebay_oauth_php_example's People

Contributors

av1d avatar

Watchers

 avatar

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.