Auth0 Device Authorization Flow Universal Link Redirect Fails on Device Code Activation Allowed Screen
Last Updated:
Overview
Mobile operating systems block programmatic redirects to HTTPS Universal Links, causing the Auth0 Device Authorization Flow to fail when returning users to a native application. Resolve this by implementing a hybrid auto-redirect with a fallback button.
In a specific use case, a mobile application scans a Quick Response (QR) code containing the device activation URL via an in-app camera scanner. The application opens the resulting authorization session in the browser, and the user completes the login and consent process. When the device-code-activation-allowed screen renders, a custom Liquid template attempts to redirect the user back into the mobile application via a Universal Link configured in application.metadata.application_callback. Review the following custom Liquid template that attempts to redirect the user back into the mobile application via a Universal Link configured in application.metadata.application_callback:
{% if prompt.name == "device-flow" and prompt.screen.name == "device-code-activation-allowed" %}
<script>
(function() {
const universalLink = '{{ application.metadata.application_callback | escape }}';
if (universalLink && universalLink.trim() !== '') {
window.location.href = universalLink;
} else {
console.error('Application callback URL not configured');
}
})();
</script>
{% else %}
{%- auth0:widget -%}
{% endif %}Applies To
- Auth0
- Device Authorization Flow
- Universal Login
- Custom HTML / Liquid Templates
- Apple iOS Safari and Google Android Chrome
Cause
Mobile operating systems implement strict security policies to prevent malicious websites from hijacking user navigation and forcefully opening applications. Apple iOS and Google Android block programmatic redirects to HTTPS Universal Links and App Links. The operating system requires a deliberate, user-initiated action, such as a physical tap on an HTML anchor (<a>) tag, to authorize a handoff from the web browser back into a native application context. When a custom Liquid template attempts to trigger the redirect automatically on page load via JavaScript, the operating system suppresses the application handoff and treats the request as standard web navigation, trapping the user in the browser.
Solution
How is the hybrid auto-redirect with a fallback button implemented?
Implement a hybrid auto-redirect with a fallback button by navigating to the Auth0 Dashboard, locating the Liquid template block, and updating the template to include an explicit HTML anchor tag.
- Navigate to the Auth0 Dashboard.
- Choose Branding > Universal Login > Advanced Options > Custom Text/HTML.
- Locate the Liquid template block governing the device flow confirmation screen (
prompt.screen.name == "device-code-activation-allowed"). - Update the template to include an explicit HTML anchor tag alongside the JavaScript redirect.
{% if prompt.name == "device-flow" and prompt.screen.name == "device-code-activation-allowed" %} <div> <h2>Activation Successful!</h2> <p>Returning you to the app...</p> <p>If you are not redirected automatically, tap the button below.</p> <!-- Explicit user-initiated action required by iOS/Android --> <a href="{{ application.metadata.application_callback | escape }}"> Return to App </a> </div> <script> (function() { const callbackUrl = '{{ application.metadata.application_callback | escape }}'; if (callbackUrl && callbackUrl.trim() !== '') { // Attempt automatic redirect // (This will likely be blocked by iOS, but may succeed on some Android environments) setTimeout(function() { window.location.href = callbackUrl; }, 500); } else { console.error('Application callback URL not configured'); } })(); </script> {% else %} {%- auth0:widget -%} {% endif %}