com.ebay.auth

eBay OAuth Android Client which helps in easy integration in Android app

License

License

Categories

Categories

CLI User Interface
GroupId

GroupId

com.ebay.auth
ArtifactId

ArtifactId

ebay-oauth-android-client
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

aar
Description

Description

com.ebay.auth
eBay OAuth Android Client which helps in easy integration in Android app
Project URL

Project URL

https://github.com/ebay/ebay-oauth-android-client/
Source Code Management

Source Code Management

https://github.com/ebay/ebay-oauth-android-client/

Download ebay-oauth-android-client

How to add to project

<!-- https://jarcasting.com/artifacts/com.ebay.auth/ebay-oauth-android-client/ -->
<dependency>
    <groupId>com.ebay.auth</groupId>
    <artifactId>ebay-oauth-android-client</artifactId>
    <version>1.0.1</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.ebay.auth/ebay-oauth-android-client/
implementation 'com.ebay.auth:ebay-oauth-android-client:1.0.1'
// https://jarcasting.com/artifacts/com.ebay.auth/ebay-oauth-android-client/
implementation ("com.ebay.auth:ebay-oauth-android-client:1.0.1")
'com.ebay.auth:ebay-oauth-android-client:aar:1.0.1'
<dependency org="com.ebay.auth" name="ebay-oauth-android-client" rev="1.0.1">
  <artifact name="ebay-oauth-android-client" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.ebay.auth', module='ebay-oauth-android-client', version='1.0.1')
)
libraryDependencies += "com.ebay.auth" % "ebay-oauth-android-client" % "1.0.1"
[com.ebay.auth/ebay-oauth-android-client "1.0.1"]

Dependencies

compile (4)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-android-extensions-runtime jar 1.3.50
org.jetbrains.kotlin : kotlin-stdlib-jdk7 jar 1.3.50
androidx.appcompat » appcompat jar 1.1.0
androidx.browser » browser jar 1.0.0

Project Modules

There are no modules declared in this project.

What is OAuth 2.0

ebay-oauth-android-client library is a simple and easy to use library to integrate your Android native app with eBay OAuth and designed to be used for OAuth specifications supported at eBay.

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.

Getting Started

To use this library, you must have an active eBay Developer Program account. The account will provide OAuth 2.0 client credentials that will allow creation of access tokens. For details, see: Creating an eBay Developer Program account

Supported Grant Types for OAuth on Native apps

eBay OAuth 2.0 on native apps only support authorization_code grant flow. Refer to eBay Developer Portal for additional details.

Obtaining a user access token through (authorization code grant flow)[https://developer.ebay.com/api-docs/static/oauth-authorization-code-grant.html] generally consists of obtaining account-owner's consent and exchanging the consent for user access token. While obtaining account-owner's consent is performed on user device, exchanging the account-owner's consent to user access token requires the use of client_secret provided in developer portal. Native apps are considered public and cannot hold the client secret securely. Please create a backend service to perform authorization code grant request securely which can be used by native app.

Native apps performs authorization code grant flow in three steps

  1. Partner app launches a consent request to get account owner’s consent
  2. On user consent, Partner app calls Partner backend service to performs authorization code grant request
  3. Partner backend service returns user access token to Partner app

This library helps perform step 1 on Android app.

Obtaining Library

This library is distributed via maven central repository. To use this library, include the below as dependency in your project

dependencies {
    compile 'com.ebay.auth:ebay-oauth-android-client:1.0.1'
}

Application Setup

Before performing OAuth, the library should be initialized with details about your application from eBay developer portal. The library uses

Use these details in ApiSessionConfiguration.initialize() as shown below:

 ApiSessionConfiguration.initialize(
                apiEnvironment = ApiEnvironment.PRODUCTION,
                apiConfiguration = ApiConfiguration(
                    <Client ID>,
                    <Redirect Uri>,
                    <space separated scopes>
                )
            )

To receive Authorization code, client app must override OauthRedirectActivity in the manifest with custom intent filters to match the registered redirect URI from eBay developer portal.

        <activity
            android:name=".oauth2.ui.OAuthRedirectActivity"
            android:exported="true"
            tools:node="replace">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:host="<registered host>"
                    android:pathPrefix="<registered path>"
                    android:scheme="https" />
            </intent-filter>
        </activity>

eBay currently supports only https redirect URI to obtain user consent. To seamlessly navigate back to your application, please create App Links by uploading Asset json file for registered Redirect URI. Details about App Links on Android can be found in Verify App Links

Get User Consent

To obtain a user's consent, In your app, use performUserAuthorization method from an activity or fragment. This method can only be called from UI Thread.

OAuthService.performUserAuthorization()

When no parameters are provided, default values provided under (Application Setup)[Application_setup] is used.

To explicitly define your configuration and parameters use

OAuthService.performUserAuthorization(
        <activity request code>,
        <ApiConfiguration>,
        <state, opaque value used to maintain state>,
        <ApiEnvironment = ApiEnvironment.PRODUCTION>,
        <GrantType = GrantType.AUTHORIZATION_CODE>)

performUserAuthorization method validates and initiates OAuth request to eBay web or native app. Users login to eBay and consent for your app to act on their behalf. Results of consent is provided in Activity.OnActivityResult() of your calling activity.

To obtain the authorization_code from the user consent use, override OnActivityResult as shown below

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)

        if (requestCode == OAuthService.OAUTH_REQUEST_CODE) {
            
            // Obtain any error from user consent
            val error = oAuthService.getAuthorizationError(data)

            // Obtain authorization code from user consent
            val code = oAuthService.getAuthorizationResponse(data)
            
        }
    }

Provide the authorization_code to your backend service to generate the user token with client secret as described in Exchanging the authorization code for a User access token guide.

How to Use Sample Mobile Application

This code contains a Sample folder containing a sample mobile application.

To get the sample working, there are two steps:

  1. Open MainActivity.kt and edit this line of code with the application credential that you obtained from the developer portal:
                apiConfiguration = ApiConfiguration(
                    "<client id>",
                    "<redirect uri>",
                    "scope_1" + " " + "scope_2"
                )
  1. Open AndroidManifest.xml and edit the redirect_uri with registered redirect_uri from developer portal
        <activity
            android:name=".oauth2.ui.OAuthRedirectActivity"
            android:exported="true"
            tools:node="replace">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:host="<registered host>"
                    android:pathPrefix="<registered path>"
                    android:scheme="https" />
            </intent-filter>

At that stage, you should be able to build and deploy the sample to an Android Emulator or Android phone, and the sample will allow a user to login to eBay and obtain user consent.

Contributions

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) 2019 eBay Inc.
Architect/Developer(s): Sangeetha Rao

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.

com.ebay.auth

eBay

https://ebay.github.io/

Versions

Version
1.0.1
1.0