Latest auth tools; Non-array catching
This commit is contained in:
@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
// LastFM app credentials
|
// LastFM app credentials
|
||||||
define('API_URL','http://ws.audioscrobbler.com/2.0/?format=json');
|
define('API_URL','http://ws.audioscrobbler.com/2.0/?format=json');
|
||||||
define('API_KEY','YOUR_KEY_HERE');
|
define('API_KEY','YOUR_API_KEY_HERE');
|
||||||
define('API_SECRET','YOUR_SECRET_HERE');
|
define('API_SECRET','YOUR_API_SECRET_HERE');
|
||||||
define('REDIRECT_URI','YOUR_REDIRECT_URI_HERE');
|
define('REDIRECT_URI','YOUR_REDIRECT_URI_HERE');
|
||||||
|
|
||||||
// Allow cross-domain requests
|
// Allow cross-domain requests
|
||||||
@ -35,7 +35,8 @@ if (isset($_GET['action'])){
|
|||||||
exit;
|
exit;
|
||||||
|
|
||||||
case 'start_session':
|
case 'start_session':
|
||||||
$session = startSession($_GET['token']);
|
$session = startSession($_GET['token'], false);
|
||||||
|
$session['origin'] = "auth_lastfm";
|
||||||
|
|
||||||
// Pass our error back to the popup opener
|
// Pass our error back to the popup opener
|
||||||
?>
|
?>
|
||||||
@ -48,13 +49,15 @@ if (isset($_GET['action'])){
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'sign_request':
|
case 'sign_request':
|
||||||
|
header('Content-Type: text/json');
|
||||||
$data = $_GET;
|
$data = $_GET;
|
||||||
$signed = signRequest($data);
|
$signed = signRequest($data);
|
||||||
echo json_encode($signed);
|
echo json_encode($signed);
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
echo 'Invalid action specified';
|
header('Content-Type: text/json');
|
||||||
|
echo '{"error": "Invalid action specified"}';
|
||||||
die();
|
die();
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -83,16 +86,15 @@ function startSession($token){
|
|||||||
if (FALSE === $ch){
|
if (FALSE === $ch){
|
||||||
throw new Exception('Failed to initialize');
|
throw new Exception('Failed to initialize');
|
||||||
}
|
}
|
||||||
|
$signature = "api_key".API_KEY."methodauth.getSessiontoken".$token.API_SECRET;
|
||||||
$data = signRequest(
|
$signature = md5($signature);
|
||||||
array(
|
$data = array(
|
||||||
"method" => "auth.getSession",
|
"api_key" => API_KEY,
|
||||||
"token" => $token
|
"api_sig" => $signature,
|
||||||
),
|
"token" => $token
|
||||||
false
|
|
||||||
);
|
);
|
||||||
|
|
||||||
curl_setopt($ch, CURLOPT_URL,API_URL);
|
curl_setopt($ch, CURLOPT_URL,API_URL."&method=auth.getSession");
|
||||||
curl_setopt($ch, CURLOPT_POST, 1);
|
curl_setopt($ch, CURLOPT_POST, 1);
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||||
@ -124,25 +126,27 @@ function startSession($token){
|
|||||||
* Perform a signed request
|
* Perform a signed request
|
||||||
*
|
*
|
||||||
* @param $data = array
|
* @param $data = array
|
||||||
* @param $post = boolean (POST request)
|
* @param $include_signatore = boolean
|
||||||
**/
|
**/
|
||||||
function signRequest($data = array(), $post = true){
|
function signRequest($data = array(), $include_signature = true){
|
||||||
unset($data['action']);
|
unset($data['action']);
|
||||||
|
|
||||||
$ch = curl_init();
|
|
||||||
|
|
||||||
if (FALSE === $ch){
|
|
||||||
throw new Exception('Failed to initialize');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure we've got our API key included
|
// Make sure we've got our API key included
|
||||||
$request = array_merge(array("api_key" => API_KEY), $data);
|
$request = array_merge(array("api_key" => API_KEY), $data);
|
||||||
|
|
||||||
|
// Drop jQuery callback argument
|
||||||
|
unset($request["_"]);
|
||||||
|
|
||||||
// Loop all the values in our request and add to our signature
|
// Loop all the values in our request and add to our signature
|
||||||
$signature = "";
|
$signature = "";
|
||||||
|
$params = "";
|
||||||
ksort($request);
|
ksort($request);
|
||||||
foreach ($request as $key => $value){
|
foreach ($request as $key => $value){
|
||||||
$signature.= $key.$value;
|
$signature.= $key.$value;
|
||||||
|
if ($params != ""){
|
||||||
|
$params.= "&";
|
||||||
|
}
|
||||||
|
$params.= $key."=".$value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finalize the signature
|
// Finalize the signature
|
||||||
@ -150,5 +154,10 @@ function signRequest($data = array(), $post = true){
|
|||||||
$signature = md5($signature);
|
$signature = md5($signature);
|
||||||
$request["api_sig"] = $signature;
|
$request["api_sig"] = $signature;
|
||||||
|
|
||||||
|
// Add finalised params as a complete string
|
||||||
|
$params.= "&api_sig=".$signature;
|
||||||
|
$request["params"] = $params;
|
||||||
|
|
||||||
return $request;
|
return $request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,16 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* Spotify Authentication proxy
|
|
||||||
*
|
|
||||||
* To use:
|
|
||||||
* 1. Create a Spotify App (https://developer.spotify.com/my-applications), and paste in your credentials below
|
|
||||||
* 2. Save this script to a publicly-accessible server
|
|
||||||
* 3. Set config in mopidy.conf to point to this script
|
|
||||||
**/
|
|
||||||
|
|
||||||
// Spotify app credentials
|
// Spotify app credentials
|
||||||
define('CLIENT_ID','YOUR_ID_HERE');
|
// Create your application here: https://developer.spotify.com/my-applications
|
||||||
define('CLIENT_SECRET','YOUR_SECRET_HERE');
|
define('CLIENT_ID','YOUR_CLIENT_ID_HERE');
|
||||||
|
define('CLIENT_SECRET','YOUR_CLIENT_SECRET_HERE');
|
||||||
define('REDIRECT_URI','YOUR_REDIRECT_URI_HERE');
|
define('REDIRECT_URI','YOUR_REDIRECT_URI_HERE');
|
||||||
|
|
||||||
// Allow cross-domain requests
|
// Allow cross-domain requests
|
||||||
@ -177,3 +170,4 @@ function refreshToken($refresh_token){
|
|||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -111,7 +111,7 @@ export let digestMopidyImages = function(mopidy, images){
|
|||||||
images[i].url = url
|
images[i].url = url
|
||||||
|
|
||||||
// Replace local images to point directly to our Mopidy server
|
// Replace local images to point directly to our Mopidy server
|
||||||
if (url.startsWith('/images/')){
|
if (url && url.startsWith('/images/')){
|
||||||
url = '//'+mopidy.host+':'+mopidy.port+url
|
url = '//'+mopidy.host+':'+mopidy.port+url
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user