Android sample applications
There are 5 different sample apps all available in the SPiD Android SDK repository that demonstrate the different ways to login to SPiD. Clone the repository in a directory of your choosing git clone https://github.com/schibsted/sdk-android.git <directory>
Before using these samples you need to configure them to use your own client credentials. Do this by finding the following code statement, replacing the placeholder values with your own valid credentials.
SPiDConfiguration config = new SPiDConfigurationBuilder()
.clientID("your-client-id")
.clientSecret("your-client-secret")
.appURLScheme("your-app-url-scheme")
.serverURL("your-spidserver-url")
.signSecret("your-secret-sign-key")
.debugMode(true)
.context(getApplicationContext())
.build();
In the AndroidManifest.xml file update the intent filter to use your own url scheme. This should be on the format <spid-clientId>
, if your client id is 123 your url scheme would be spid-123. This is used to redirect http calls to your app
<data android:scheme="your-app-url-scheme" />
The sample apps show how to login natively, browser, webview, or via a user's Facebook or Google+ accounts. If the user is already authenticated when the app launches the user is forwarded to the redirect url. This is especially useful if you use a browser to login as the cookie from another application using SPiD to login can be used by your application, simplifying the login process for the user and increasing the conversion rate in your app.
SPiDExampleApp
This app shows how to login using either a browser or a SPiD webview.
SPiDNativeApp
The native app logs in to SPiD by username and password using the OAuth password grant type.
SPiDHybridApp
The hybrid app demonstrates a hybrid app that logs in using a webview.
SPiDFacebookApp
The SPiD Facebook sample app shows how to login or create a SPiD account using a user's Facebook account. To test the Facebook app you need to acquire a Facebook app id. To do that you need to first register as a Facebook developer if you are not already one. Once that is done you can acquire a Facebook app id for your application by registering a new app; My Apps->Add a New App. Set the facebook_app_id in values/strings.xml to your newly acquired app id. You must also add the Facebook dependency in your gradle file. To add it you also need to add the mavenCentral() to your repositories if you don’t already have it.
repositories {
mavenCentral()
}
dependencies {
compile 'com.facebook.android:facebook-android-sdk:3.23.0'
}
SPiDGooglePlusApp
The SPiD Google plus app demonstrates logging in through Google plus, or creating a SPiD account from a Google+ account. If you want to implement Google+ login in your own project you have to create a Google project for it in the Google developers console.
1) Create a new project in the Google Developer Console
2) Enable the Google+ API under APIs
3) Make sure Google+ API is displayed under Enabled APIs
4) Create your OAuth Client, choose the Installed application type
5) Configure your consent screen. Add at least your product name, other fields are optional
6) Once you save the consent screen the create client ID should automatically be shown. Choose Installed application and Android. Your package name must conform to what you use in your app. To find your signing certificate fingerprint use the Java keytool command. The default location of the debug keystore is ~/.android/debug.keystore, copy the value for the SHA1 fingerprint.
keytool -list -v -keystore <keystore>
7) Update the credentials in your app, add your uri scheme in the AndroidManifest and verify that you can run the app and login using Google+.
More about the Android SDK
- Overview
- Getting started
- Register
- Self Service
- Login
- Android
- Android sample apps
- iOS
- Mobile review checklist
- OAuth for mobile clients
- Best practices
- FAQ
Help us improve
Did you spot an error? Or maybe you just have a suggestion for how we can improve? Leave a comment, or better yet, send us a pull request on GitHub to fix it (in-browser editing, only takes a moment).
Comments/feedback
Do you have questions, or just want to contribute some newly gained insight? Want to share an example? Please leave a comment. SPiD reads and responds to every question. Additionally, your experience can help others using SPiD, and it can help us continuously improve our documentation.