Skip to content

Commit

Permalink
Merge pull request #110 from auth0/schemePlaceholder
Browse files Browse the repository at this point in the history
Add a manifest placeholder for configuring the scheme
  • Loading branch information
hzalaz authored Jul 19, 2017
2 parents e70ad65 + 284d9c8 commit 915d86c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ https://{YOUR_AUTH0_DOMAIN}/android/{YOUR_APP_PACKAGE_NAME}/callback
Remember to replace `{YOUR_APP_PACKAGE_NAME}` with your actual application's package name, available in your `app/build.gradle` file as the `applicationId` value.


Next, define a placeholder for the Auth0 Domain which is going to be used internally by the library to register an **intent-filter**. Go to your application's `build.gradle` file and add the `manifestPlaceholders` line as shown below:
Next, define the Manifest Placeholders for the Auth0 Domain and Scheme which are going to be used internally by the library to register an **intent-filter**. Go to your application's `build.gradle` file and add the `manifestPlaceholders` line as shown below:

```groovy
apply plugin: 'com.android.application'
Expand All @@ -95,16 +95,16 @@ android {
//...
//---> Add the next line
manifestPlaceholders = [auth0Domain: "@string/auth0_domain"]
manifestPlaceholders = [auth0Domain: "@string/auth0_domain", auth0Scheme: "https"]
//<---
}
//...
}
```

It's a good practice to define reusable resources like `@string/auth0_domain` but you can also hard code the value in the file.
It's a good practice to define reusable resources like `@string/auth0_domain` but you can also hard code the value in the file. The scheme value can be either `https` or a [custom scheme](#a-note-about-app-deep-linking).

Alternatively, you can declare the `RedirectActivity` in the `AndroidManifest.xml` file with your own **intent-filter** so it overrides the library's default. If you do this then the `manifestPlaceholders` don't need to be set as long as the activity contains the `tools:node="replace"` like in the snippet below. If you choose to use a [custom scheme](#a-note-about-app-deep-linking) you must define your own intent-filter as explained below.
Alternatively, you can declare the `RedirectActivity` in the `AndroidManifest.xml` file with your own **intent-filter** so it overrides the library's default. If you do this then the `manifestPlaceholders` don't need to be set as long as the activity contains the `tools:node="replace"` like in the snippet below.

In your manifest inside your application's tag add the `RedirectActivity` declaration:

Expand Down Expand Up @@ -160,11 +160,11 @@ If you've followed the configuration steps, the authentication result will be re

##### A note about App Deep Linking:

Currently, the default scheme used in the Callback Uri is `https`. This works best for Android API 23 or newer if you're using [Android App Links](https://developer.android.com/training/app-links/index.html), but in previous Android versions this may show the intent chooser dialog prompting the user to chose either your application or the browser. You can change this behaviour by using a custom unique scheme, so that the OS opens directly the link with your app.
If you've followed this document configuration steps you've noticed that the default scheme used in the Callback Uri is `https`. This works best for Android API 23 or newer if you're using [Android App Links](https://developer.android.com/training/app-links/index.html), but in previous Android versions this may show the intent chooser dialog prompting the user to chose either your application or the browser. You can change this behaviour by using a custom unique scheme so that the OS opens directly the link with your app.

1. Update the intent filter in the Android Manifest and change the custom scheme.
1. Update the `auth0Scheme` Manifest Placeholder on the `app/build.gradle` file or update the intent-filter declaration in the `AndroidManifest.xml` to use the new scheme.
2. Update the allowed callback urls in your [Auth0 Dashboard](https://manage.auth0.com/#/applications) client's settings.
3. Call `withScheme()` passing the scheme you want to use.
3. Call `withScheme()` passing the custom scheme you want to use.


```java
Expand Down
2 changes: 1 addition & 1 deletion auth0/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ android {
buildTypes {
debug {
//Helps tests. buildTypes values are not included in the merged manifest
manifestPlaceholders = [auth0Domain: "auth0.test.domain"]
manifestPlaceholders = [auth0Domain: "auth0.test.domain", auth0Scheme: "https"]
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions auth0/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<activity
android:name="com.auth0.android.provider.RedirectActivity"
android:exported="true">
<intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
Expand All @@ -46,7 +46,7 @@
<data
android:host="${auth0Domain}"
android:pathPrefix="/android/${applicationId}/callback"
android:scheme="https" />
android:scheme="${auth0Scheme}" />
</intent-filter>
</activity>

Expand Down

0 comments on commit 915d86c

Please sign in to comment.