developers

A New Android Sample

A new sample is now available on our repo for Android developers. The sample demonstrates integration with Auth0 for authentication

Jun 20, 20132 min read

A new sample is now available on our repo for Android developers. The sample demonstrates integration with Auth0 for authentication and uses the standard techinque of delegating the authentication process to an embeded web view (extending the WebViewClient class).

All interactions are encapuslated in an Activity that you can call like in this example below:

Button login = (Button) findViewById(R.id.login);
login.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        Intent authActivity = new Intent(MainActivity.this,
                com.auth0.sdk.auth0sample.AuthenticationActivity.class);

        AuthenticationActivitySetup setup;
        setup = new AuthenticationActivitySetup(Tenant, ClientID, Callback, Connection);

        authActivity.putExtra(AuthenticationActivity.AUTHENTICATION_SETUP, setup);

        startActivityForResult(authActivity, AuthenticationActivity.AUTH_REQUEST_COMPLETE);
    }
});

The result is returned using the standard method of overriding the onActivityResult method:

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

    switch(requestCode)
    {
        case AuthenticationActivity.AUTH_REQUEST_COMPLETE:
            if(resultCode==RESULT_OK)
            {
                AuthenticationActivityResult result;
                result = (AuthenticationActivityResult) authActivityResult.getSerializableExtra(AuthenticationActivity.AUTHENTICATION_RESULT);

                ((TextView) findViewById(R.id.access_token)).setText(result.accessToken);
                ((TextView) findViewById(R.id.jwt)).setText(result.JsonWebToken);
            }
            break;
    }
}

The AuthenticationActivityResult class is just a container for the two tokens you can use to call APIs:

public class AuthenticationActivityResult implements Serializable {
    public String accessToken;
    public String JsonWebToken;
}

If your app in Auth0 is created as Windows Azure Mobile Services:

Then the Json Web Token will be compatible with what Mobile Services expects. See this previous post for more details.

An end to end tutorial is available here.

We are working on a similar sample using Xamarin. Stay tuned!

Try Auth0 yourself!

About the author

Eugenio Pace

Eugenio Pace

CEO and Co-Founder

Pace co-founded Auth0 in early 2013 with CTO and “brother-in-arms” Matias Woloski while living 7,000 miles apart from each other. Since then, Pace has played an instrumental role in growing Auth0 into a leading identity management company that is loved by developers and trusted by global enterprises. He loves traveling and has visited more than 35 countries for business and pleasure. He currently lives in Redmond, Washington with his wife, two sons, and their labrador retriever. In his spare time, he enjoys the outdoors, rowing, riding bikes, spending time with his family, restoring his 1970 Karmann Ghia, writing his blog, and reading history and philosophy.View profile