2012-05-17 20 views
0

我試圖在Spotify應用程序中完成OAuth身份驗證。默認情況下,window.open被阻止,我不確定是否有任何解決方法。所以,我想知道處理這個問題的最好方法是什麼。我希望能夠執行以下操作: 1)將用戶重定向到身份驗證鏈接 2)通過身份驗證後,我希望能夠得到通知來處理返回URL並從中提取訪問令牌。Spotify應用程序中的OAuth

有幾個選項,我正在考慮:1) IFrame2) $.ajax() -- problem is, this doesn't seem to load all javascript/css files from the auth url properly.

有什麼建議?

回答

0

我相信auth.showAuthenticationDialog() API正是你所追求的。它會彈出一個對話框顯示給定的URL,然後在返回URL被調用時返回參數。文檔here

var sp = getSpotifyApi(1); 
var auth = sp.require('sp://import/scripts/api/auth'); 

auth.showAuthenticationDialog('http://www.last.fm/api/auth/?api_key=LAST_FM_API_KEY&cb=sp://my_app_name', 'sp://my_app_name', { 

    onSuccess : function(response) { 
     // Response will be something like 'sp://my_app_name?token=xxxxxxx' 
     console.log("Success! Here's the response URL: " + response); 
    }, 

    onFailure : function(error) { 
     console.log("Authentication failed with error: " + error); 
    }, 

    onComplete : function() { } 
}); 
+0

輝煌!非常感謝! – OneDeveloper