22

I am testing the following example to authenticate a user by logging in and redirecting to the auth screen - http://jsfiddle.net/JMPerez/j1sqq4g0/

This example uses a callback page with the following script:

(function() {
  var hash = {};
  window.location.hash.replace(/^#\/?/, '').split('&').forEach(function(kv) {
    var spl = kv.indexOf('=');
    if (spl != -1) {
      hash[kv.substring(0, spl)] = decodeURIComponent(kv.substring(spl+1));
    }
  });

  console.log('initial hash', hash);

  if (hash.access_token) {
    window.opener.postMessage(
      JSON.stringify({
        type:'access_token',
        access_token: hash.access_token,
        expires_in: hash.expires_in || 0
      }), 
      'http://fiddle.jshell.net'
    );
    window.close();
  }
})();

When trying on mobile, it will open a new tab in Safari. Is it possible to check if the app if installed on iOS and login via that instead? Will make the process much quicker.

As seen in an issue here, it seems resolved but cannot understand what is triggering it to do so? - https://github.com/spotify/web-api/issues/718

Thanks!

streletss
  • 4,305
  • 4
  • 14
  • 34
scopeak
  • 555
  • 3
  • 17
  • 2
    Unfortunately, it's not possible to check if an app is installed with iOS, there used to be workarounds but most are no longer working, this is due to privacy issue to prevent ad companies from identifying and fingerprinting users. – James Wong Jun 22 '18 at 05:54
  • I think if the app is installed and you open the correct link which are universal links implemented by `Spotify app` then it should launch the app. I suspect that the login link is a universal link and it should open the Spotify App. – Inus Saha Jun 23 '18 at 05:12
  • 1
    If the URI begins with spotify:// instead of https:// then the device will open the corresponding application. This works on any desktop and android devices. I can't tell for iOS and also the link parameters are different then I guess. Thus it's not a problem with Spotify itself, because the Browser is there to fulfill requests with the HTTP protocol. – NoNickAvailable Aug 03 '20 at 21:12
  • I've worked with the Spotify API for some time now and I've not seen that this is possible. I had another look to check and it doesn't look like the Spotify app currently supports this. https://developer.spotify.com/documentation/general/guides/authorization-guide/ In my experience the Spotify API is very limited and seems dated, lacking many of the new fatures available in the offical app even today. – James Webb Jan 18 '21 at 11:23

1 Answers1

1

To summarize here's an aggregated answer:

  • iOS doesn't allow for looking what apps are installed on your device, neither does Android.
  • Using universal links (both on Android and iOS), you generally speaking may generate a link that opens an app, but for this, the corresponsing App needs to register this connection on your device.
  • For Spotify especially, I don't think that the Spotify-app has registered such a link. It's not usual that native Apps trigger for authentication only, so it's unlikely that Spotify does.