auth0/android-gradle-credentials

Name: android-gradle-credentials

Owner: Auth0

Description: Gradle Plugin to generate Auth0 Credentials from properties file.

Created: 2016-10-04 20:53:28.0

Updated: 2017-05-25 19:37:43.0

Pushed: 2016-11-24 18:11:46.0

Homepage:

Size: 135

Language: Groovy

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Auth0 Android Gradle-Credentials Plugin

JitPack Gradle GitHub tag license

This plugin generates an XML file with the required Auth0 credentials. It creates a new a Task generate{buildVariant}Auth0Credentials to generate the String resources in each build folder. This task attaches automatically to the Build process, and can handle incremental builds.

Setup
Using Gradle

This is the RECOMMENDED approach. Add the Gradle's Maven url to the buildscript/repositories list and also add the plugin to the buildscript/classpath inside the project's build.gradle file:

dscript {
repositories {
    jcenter()
    //...
    maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
    classpath 'com.android.tools.build:gradle:2.2.2'
    //...
    classpath 'gradle.plugin.com.auth0.android:gradle-credentials:1.0.1'
}

Then go to your application's build.gradle file and apply the gradle-credentials plugin after the android.application plugin.

y plugin: 'com.android.application'
y plugin: 'com.auth0.android.gradle-credentials'

..
Using JitPack

Add JitPack to the buildscript/repositories list and also add the plugin to the buildscript/classpath inside the project's build.gradle file:

dscript {
repositories {
    jcenter()
    //...
    maven { url "https://jitpack.io" }
}
dependencies {
    classpath 'com.android.tools.build:gradle:2.2.1'
    //...
    classpath 'com.github.auth0:android-gradle-credentials:master-SNAPSHOT'
}

Then go to your application's build.gradle file and apply the gradle-credentials plugin after the android.application plugin.

y plugin: 'com.android.application'
y plugin: 'com.auth0.android.gradle-credentials'

..
Using a fresh local build
  1. Clone or download this project.
  2. Run ./gradlew clean build install so the plugin installs in the mavenLocal() repository.

Add the plugin dependency. Go to your project's build.gradle file and add:

dscript {
repositories {
    mavenLocal()
    //...
}
dependencies {
    classpath 'com.auth0.android:gradle-credentials:1.0.0'
    //...
}

Then go to your application's build.gradle file and apply the gradle-credentials plugin after the android.application plugin.

y plugin: 'com.android.application'
y plugin: 'com.auth0.android.gradle-credentials'

..
How it Works

The plugin will try to find the Auth0 Credentials in one of the following locations in this order:

  1. User's Home local.properties file. This is the RECOMMENDED location as you only need to setup once your credentials and it will work for every project.
  2. Project's local.properties file. This location is also RECOMMENDED as this file shouldn't be committed/pushed to the repository, the credentials will always remain private.
  3. The Application's Module build.gradle file.

If either the domain or the clientId key/values are missing, the plugin will try to search for them in the next location. If they can't be found in the last location, it will throw an exception and won't let you build the project.

Credentials in a local.properties file

Find the local.properties file in your User's Home directory or in your Project's Home directory. Next, add the following auth0 key/values:

..

0.domain=lbalmaceda.auth0.com                   //Auth0 Domain
0.clientId=1Wu12gnhRRYh31v9SfB3c6I3bIJdRIze     //Auth0.Lock Client ID
0.guardian.domain=guardian-domain               //Auth0.Guardian Domain

If the local.properties file doesn't exist in your Project's Home directory, try to sync or build your project and the Android Studio IDE will generate it for you. If you want to use your User's Home directory, you will need to create it manually.

Credentials in a build.gradle file

Find your Application's build.gradle file. Next, add the auth0 closure with domain and lock.clientId key/values.

lugins are applied here

oid {
// ...


ndencies {
// ...


..

0 {
domain 'lbalmaceda.auth0.com'                 //Auth0 Domain
clientId '1Wu12gnhRRYh31v9SfB3c6I3bIJdRIze'   //Auth0.Lock Client ID
guardian {
    domain 'guardian-domain'                  //Auth0.Guardian Domain
}

Access the Credentials

After you build your project or manually run the Auth0Credentials task, the credentials will be available in the Android Resources. Access them with the R constant:

ing domain = getResources().getString(R.string.com_auth0_domain);`
ing clientId = getResources().getString(R.string.com_auth0_client_id);`
ing guardianDomain = getResources().getString(R.string.com_auth0_guardian_domain);`
Run the Plugin

The plugin runs automatically with each project build. If you want, you can manually run the task by calling ./gradlew generate{buildVariant}Auth0Credentials with your preferred buildVariant.

AndroidProject ??? ./gradlew generateDebugAuth0Credentials

llel execution is an incubating feature.
emental java compilation is an incubating feature.
0Credentials: Searching in build.gradle:auth0 closure
0Credentials: Using ClientID=1Wu12gnhRRYh31v9SfB3c6I3bIJdRIze and Domain=lbalmaceda.auth0.com
:generateDebugAuth0Credentials UP-TO-DATE

D SUCCESSFUL

l time: 2.732 secs

The output will be located in the build/intermediates/res/merged/{VARIANT}/values/auth0.xml.

License

This project is licensed under the MIT License.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.