Authentication

Overview

The login flow is a standard OAuth 2.0 Access Token flow using the browser. When a user clicks on a login button, the browser is opened using an Intent created by the app and the user is presented with the Nike Plus login page. The user enters their Nike credentials and success or failure is returned to the app in the form of a browser redirect. If authentication is successful, the Intent fired by the browser is handled by the application to exchange the authorization code for an access token. The SDK provides functions to handle this flow.

Begin Login

The application must be configured to handle the redirect URL Intent that will be fired after the web based login is complete.
        <activity
            android:name="com.application.HandleLoginFlow"
            android:label="@string/app_name"
            android:launchMode="singleTop" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <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="nike.com"
                    android:pathPrefix="/login"
                    <!-- Use the pattern 'nike-clientId' for the scheme -->
                    android:scheme="nike-12345####" />
            </intent-filter>
        </activity>
The next step is to initiate the login flow by calling the SDK. Pass a NikeConfig object and the application context to the Nike login method.
NikeFacade.login(new NikeConfigObject(), getContext());

Handle Redirect Intent

After the user has completed the web authentication flow, the browser will fire an Intent containing the auth code information. This intent can be passed to the SDK, and the SDK will exchange the auth code for an access token. A handler is notified of success or failure. The handler is required to conform to the NikeLoginHandler interface.
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  NikeFacade.handleLoginIntent(this.getIntent(), new NikeConfigObject(), getContext(), new NikeLoginHandler());
  }
}
After the SDK has successfully exchanged the authorization code for a token, the Credential object contains the access token, refresh token and related information. This object is available from NikeFacade.getCredential. Leveraging the Nike+ Android SDK is the preferred method, as there is a lot of work put into making hte login flow the best experience for the app and the user, but the API the Nike+ Android SDK uses is available. Please refer to the  code level documentation for details.