Android SDK for Userbin

Use this SDK to authenticate your users through Userbin in your Android application.

Install / Run

  1. Clone this repo

    git clone git@github.com:userbin/userbin-android-example.git
    
  2. Open Eclipse ADT

  3. Import project by

    • Selecting File -> Import...
    • Android -> Existing Android Code Into Workspace
    • Point root to cloned repo and click finish
  4. Open MainActivity.java and set your credentials

  5. Press play and you should be all set

Usage

Check out MainActivity.java for a reference implementation of how to open and handle the response from the authentication dialog. Remember to change the credentials to your own..

Here is a few things that will help you get started when you are making your own app.

Configuration

Userbin credentials is set via the UserbinConfiguration object. Eg.

UserbinConfiguration config = new UserbinConfiguration(
  "APP_ID",
  "API_SECRET"
);

In the activity from which you will open the authentication dialog, you must finish the authentication process by overriding the onActivityResult method:

// Inside an Activity
private Userbin mUserbin;

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent authActivityResult) {
  super.onActivityResult(requestCode, resultCode, authActivityResult);
  mUserbin.finishAuthenticationActivity(requestCode, resultCode, authActivityResult);
}

This requires that you have an instance of the Userbin object available (here called mUserbin)

The Userbin object

/* Create a new instance of the Userbin object with a configuration */
Userbin userbin = new Userbin(config);

/* Opens the log in dialog and invokes the callback when done (`this` refers to the current activity) */
userbin.logIn(this, new UserbinAuthenticationCallback() {
  @Override
  public done(code) {
    JSONObject profile = userbin.getCurrentProfile();
  }
});

/* Opens the sign up dialog in the same way as `logIn` */
userbin.signUp(this, ...);

/* Returns the currently logged in user profile as a `JSONObject` or null if not logged in */
JSONObject profile = userbin.getCurrentProfile();

Authenticating towards your own server

At some point you will probably want to fetch data from your own server (such as the TODO items for the currently logged in user). If you are using any of our server libraries on your backend, authenticating is as simple as setting a cookie _ubt with the content returned from userbin.getCurrentJWT() on the outgoing requests.

Admin dashboard

With Userbin you get an admin dashboard out of the box.

  • Invite, update, remove and ban users
  • Log in as any of your users for debugging
  • Configure user validation, access rights and login methods
  • See who is using your web or mobile app in real-time.
  • Customize copy and appearance of your transactional emails.