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.
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:
buildscript {
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.
apply plugin: 'com.android.application'
apply plugin: 'com.auth0.android.gradle-credentials'
// ...
Add JitPack to the buildscript/repositories list and also add the plugin to the buildscript/classpath inside the project's build.gradle
file:
buildscript {
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.
apply plugin: 'com.android.application'
apply plugin: 'com.auth0.android.gradle-credentials'
// ...
- Clone or download this project.
- 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:
buildscript {
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.
apply plugin: 'com.android.application'
apply plugin: 'com.auth0.android.gradle-credentials'
// ...
The plugin will try to find the Auth0 Credentials in one of the following locations in this order:
- 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. - 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. - 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. **
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:
// ...
auth0.domain=lbalmaceda.auth0.com //Auth0 Domain
auth0.clientId=1Wu12gnhRRYh31v9SfB3c6I3bIJdRIze //Auth0.Lock Client ID
auth0.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.
Find your Application's build.gradle
file. Next, add the auth0
closure with domain
and lock.clientId
key/values.
// Plugins are applied here
android {
// ...
}
dependencies {
// ...
}
// ...
auth0 {
domain 'lbalmaceda.auth0.com' //Auth0 Domain
clientId '1Wu12gnhRRYh31v9SfB3c6I3bIJdRIze' //Auth0.Lock Client ID
guardian {
domain 'guardian-domain' //Auth0.Guardian Domain
}
}
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:
`String domain = getResources().getString(R.string.com_auth0_domain);`
`String clientId = getResources().getString(R.string.com_auth0_client_id);`
`String guardianDomain = getResources().getString(R.string.com_auth0_guardian_domain);`
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.
~/MyAndroidProject ❯❯❯ ./gradlew generateDebugAuth0Credentials
Parallel execution is an incubating feature.
Incremental java compilation is an incubating feature.
Auth0Credentials: Searching in build.gradle:auth0 closure
Auth0Credentials: Using ClientID=1Wu12gnhRRYh31v9SfB3c6I3bIJdRIze and Domain=lbalmaceda.auth0.com
:app:generateDebugAuth0Credentials UP-TO-DATE
BUILD SUCCESSFUL
Total time: 2.732 secs
The output will be located in the build/intermediates/res/merged/{VARIANT}/values/auth0.xml
.
This project is licensed under the MIT License.