ebay java_ebay-oauth-java-client

eBay OAuth Client Library (Java)

ebay-oauth-java-client.svg?branch=master

badge.svg

ebay-oauth-java-client.svg

eBay OAuth client library is a simple and easy-to-use library for integrating with eBay OAuth and designed to be used for OAuth 2.0 specification supported by eBay. There are multiple standard clients that can be used with eBay OAuth, such as Spring OAuth client. However, this library in addition to functioning as a simple eBay OAuth client, helps with additional features such as cached App tokens. There are also future enhancements planned to add id_token support, 'login with eBay' support etc.,

What is OAuth 2.0

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 is available at developer.ebay.com.

Supported Languages

This is created as a Maven based Java project and can be used as a dependency in a Java based application or other JVM based languages such as Groovy, Scala etc.,

Installation

Current Version : 1.1.0

Add following to section of your pom.xml as given below

com.ebay.auth

ebay-oauth-java-client

1.1.0

Getting Started

All interactions with this library can be performed using OAuth2Api oauth2Api = new OAuth2Api();

Library Setup and getting started

Ensure you have a config file in your source code of type YAML. Refer to ebay-config-sample.yaml.

This file would hold all your application credentials such as AppId, DevId, and CertId. Refer to Creating eBay Developer Account for details on how to get these credentials.

Once the file is created, call CredentialUtil.load(new FileInputStream()); to load the credentials.

It is recommended to load the credentials during startup time (initialization) to prevent runtime delays.

Once the credentials are loaded, call any operation on OAuth2Api

Types of Tokens

There are mainly two types of tokens in usage.

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

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

All of the regular OAuth 2.0 specifications such as client_credentials, authorization_code, and refresh_token are all supported. Refer to eBay Developer Portal

Grant Type: Client Credentials

This grant type can be performed by simply using OAuth2Api.getApplicationToken(). Read more about this grant type at oauth-client-credentials-grant

Grant Type: Authorization Code

This grant type can be performed by a two step process. Call OAuth2Api.generateUserAuthorizationUrl() to get the Authorization URL to redirect the user to. Once the user authenticates and approves the consent, the callback need to be captured by the redirect URL setup by the app and then call OAuth2Api.exchangeCodeForAccessToken() to get the refresh and access tokens.

Grant Type: Refresh Token

This grant type can be performed by simply using OAuth2Api.getAccessToken(). Usually access tokens are short lived and if the access token is expired, the caller can use the refresh token to generate a new access token. Read more about it at Using a refresh token to update a user access token

Grant Type: Id Token (OpenID Connect)

This grant type is added to support the OpenID connect protocol for generating an Id token which helps provide identity federation without any API access. This protocol is usually helpful when a functionality such as "Login via eBay" is required without any need for access tokens.

This is a two step process. The URL to redirect the user can be generated via OAuth2Api.generateIdTokenUrl(). Once the user authenticates to eBay site, the callback redirect URL will be invoked with the id_token as an additional parameter. The validity of the id_token can be verified and the verified attributes extracted using EbayIdTokenValidator.validate(). Ensure that only the authorized clientIds are passed to the function to verify if the id_token has been issued to one of those clients only.

This method also verifies the signature, the expiration and issuer of the id_token before returning back the verified attributes.

33f59cf2e912f2448b7ca187376dedc8.png

It is also a good practice to send a unique nonce in every request and verify if the id_token has been issued only for that nonce.

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.

Before you commit

Libraries used

okhttp

gson

SnakeYAML

joda-time

slf4j

commons-lang

json

jackson-databind

Versions

The current version of the library is 1.1.0 and supports the following features.

1. OAuth 2.0 specification for Access and Refresh tokens

2. OpenID connect based id_token support

Developers and Contributors

License

Copyright (c) 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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值