Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spotify Web API - Authenticate user via native mobile app rather than browser?

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!

like image 557
scopeak Avatar asked Jun 02 '18 07:06

scopeak


People also ask

How do I authenticate my Spotify account?

The authorization process requires valid client credentials: a client ID and a client secret. You can follow the App settings guide to learn how to generate them. Once the authorization is granted, the authorization server issues an access token, which is used to make API calls on behalf the user or application.

How do I get an access token for Spotify Web API?

Request Access Token If the user accepted your request, then your app is ready to exchange the authorization code for an Access Token. It can do this by making a POST request to the /api/token endpoint. This field must contain the value "authorization_code" . The authorization code returned from the previous request.


1 Answers

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.
like image 182
SimplyComple0x78 Avatar answered Oct 07 '22 11:10

SimplyComple0x78