Android Rules

Rules are functions written in JavaScript that are executed in Auth0 as part of the transaction every time a user authenticates to your application. For more information about Auth0 rules, please refer to the full documentation.

Download a sample project.

Before Starting

Make sure you have completed either the Login or the Custom Login examples.

Create a Rule

To create a rule, you need to go to the new rule page. From there, you can either use a predefined template or create one from scratch.

In this example we will use "Add country to the user profile" template, under the Enrich Profile section:

Add country template

This rule gets the country_name from the context and adds it as a new country attribute to the user profile.

Country rule sample

This is just a basic template. You can edit it to meet your business needs. Once you are done, save the rule and that's it. Whenever your users log in, the rule will be executed and their country will be added.

Test the Rule

To see the newly created rule working, just implement a login and check the user profile information (you can find out how to do this in the user profile tutorial).

You can access the country added by the rule within the extraInfo hashmap from the userProfile object you receive in the callback (named payload by default):

    .start(new BaseCallback<UserProfile, AuthenticationException>() {

  public void onSuccess(final UserProfile userProfile) {
    runOnUiThread(new Runnable() {
      public void run() {
        // Get the country from the user profile
        if (payload.getExtraInfo().containsKey("country")){
          String country = (String) payload.getExtraInfo().get("country");
          //Show the country

  public void onFailure(AuthenticationException error) {

Previous Tutorial
6. Linking Accounts
Next Tutorial
8. Authorization
Try Auth0 for FREECreate free Account