I am working on integrating Spotify's OAuth authentication into a web application for mobile users. The goal is to enable users to authenticate via the Spotify mobile app on Android devices, ensuring compatibility with popular browsers like Chrome Mobile and in-app browsers such as those in Instagram, Facebook, and TikTok.
"MY APP" here is the client that requests access to the protected resources (i.e. my web app). I am following the Spotify Authorization Code Flow, and my current implementation is as follows:
const urlQueryParams = '?scope=user-read-email&response_type=code&redirect_uri=[ENCODED_REDIRECT_URI]&state=[STATE]&client_id=[CLIENT_ID]';
onclick: function () {
let url = 'https://accounts.spotify.com/authorize';
url += urlQueryParams;
window.location.href = url;
}
This code works, but it always prompts users to authenticate through the Spotify Auth webpage, even if they have the Spotify app installed and are logged in. This process is inconvenient for mobile users. I saw in similar questions that a redirect from web to app should happen autonomously, provided the user has the app installed, but according to my own testing it doesn't happen for /authorize page.
For the sake of clarity, let's assume that the Spotify app for Android is always installed and End User is authenticated inside the app.
I've tried the following approach:
const urlQueryParams = '...';
onclick: function () {
let url = 'https://accounts.spotify.com/inapp-authorize';
url += urlQueryParams;
window.location.href = url;
}
This method sometimes behaves like a deep link, opening the Spotify app for Android and redirecting users back to My App if they have previously granted access. It works in Chrome Mobile but not in Instagram's webview. It asks user to login via webpage inside Instagram. Also it stucks on infinite "Loading..." inside Spotify app if users have NOT previously granted access to My App.
I also experimented with an intent:// schema:
const urlQueryParams = '...';
onclick: function () {
let url = 'intent://accounts.spotify.com/inapp-authorize';
url += urlQueryParams + '#Intent;package=com.spotify.music;scheme=spotify;end';
window.location.href = url;
}
This approach always prompts users to continue in the Spotify app, but it leads them to the Home page instead of the Login page.
I am aware of the spotify:// schema for deep linking to albums, artists, and tracks in the Spotify app. However, I'm unsure how to use it to deep link directly to the Auth page in the Spotify app for Android.
I am seeking a reliable solution for authenticating users via the Spotify app across different mobile browsers and in-app webviews. Insights from Spotify engineers or anyone with relevant experience would be highly appreciated.
Here's a minimal reproducible example on jsFiddle. Additional details, such as demo screenshots, can be provided upon request.

Instagram's webview, that's Instagram's problem, isn't it? Not Spotify's problem. My assumption is that Instagram's webview doesn't support deeplinking, and therefore you should be looking for help withInstagram's webviews, not help with Spotify.