Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a manifest placeholder for configuring the scheme #110

Merged
merged 1 commit into from
Jul 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this break if we specify custom scheme?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't break, at least compiler doesn't scream and the apk installs and runs ok. The reason I added is because people using app links would otherwise need to manually override this intent-filter declaration with their own in the manifest.

<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