Latest auth tools; Non-array catching
This commit is contained in:
@ -11,8 +11,8 @@
|
||||
|
||||
// LastFM app credentials
|
||||
define('API_URL','http://ws.audioscrobbler.com/2.0/?format=json');
|
||||
define('API_KEY','YOUR_KEY_HERE');
|
||||
define('API_SECRET','YOUR_SECRET_HERE');
|
||||
define('API_KEY','YOUR_API_KEY_HERE');
|
||||
define('API_SECRET','YOUR_API_SECRET_HERE');
|
||||
define('REDIRECT_URI','YOUR_REDIRECT_URI_HERE');
|
||||
|
||||
// Allow cross-domain requests
|
||||
@ -35,7 +35,8 @@ if (isset($_GET['action'])){
|
||||
exit;
|
||||
|
||||
case 'start_session':
|
||||
$session = startSession($_GET['token']);
|
||||
$session = startSession($_GET['token'], false);
|
||||
$session['origin'] = "auth_lastfm";
|
||||
|
||||
// Pass our error back to the popup opener
|
||||
?>
|
||||
@ -47,14 +48,16 @@ if (isset($_GET['action'])){
|
||||
|
||||
break;
|
||||
|
||||
case 'sign_request':
|
||||
case 'sign_request':
|
||||
header('Content-Type: text/json');
|
||||
$data = $_GET;
|
||||
$signed = signRequest($data);
|
||||
echo json_encode($signed);
|
||||
exit;
|
||||
|
||||
default:
|
||||
echo 'Invalid action specified';
|
||||
header('Content-Type: text/json');
|
||||
echo '{"error": "Invalid action specified"}';
|
||||
die();
|
||||
|
||||
}
|
||||
@ -83,16 +86,15 @@ function startSession($token){
|
||||
if (FALSE === $ch){
|
||||
throw new Exception('Failed to initialize');
|
||||
}
|
||||
|
||||
$data = signRequest(
|
||||
array(
|
||||
"method" => "auth.getSession",
|
||||
"token" => $token
|
||||
),
|
||||
false
|
||||
$signature = "api_key".API_KEY."methodauth.getSessiontoken".$token.API_SECRET;
|
||||
$signature = md5($signature);
|
||||
$data = array(
|
||||
"api_key" => API_KEY,
|
||||
"api_sig" => $signature,
|
||||
"token" => $token
|
||||
);
|
||||
|
||||
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_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
@ -124,31 +126,38 @@ function startSession($token){
|
||||
* Perform a signed request
|
||||
*
|
||||
* @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']);
|
||||
|
||||
$ch = curl_init();
|
||||
|
||||
if (FALSE === $ch){
|
||||
throw new Exception('Failed to initialize');
|
||||
}
|
||||
|
||||
// Make sure we've got our API key included
|
||||
$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
|
||||
$signature = "";
|
||||
$params = "";
|
||||
ksort($request);
|
||||
foreach ($request as $key => $value){
|
||||
$signature.= $key.$value;
|
||||
if ($params != ""){
|
||||
$params.= "&";
|
||||
}
|
||||
$params.= $key."=".$value;
|
||||
}
|
||||
|
||||
|
||||
// Finalize the signature
|
||||
$signature.= API_SECRET;
|
||||
$signature = md5($signature);
|
||||
$request["api_sig"] = $signature;
|
||||
|
||||
// Add finalised params as a complete string
|
||||
$params.= "&api_sig=".$signature;
|
||||
$request["params"] = $params;
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
||||
|
||||
@ -1,16 +1,9 @@
|
||||
<?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
|
||||
define('CLIENT_ID','YOUR_ID_HERE');
|
||||
define('CLIENT_SECRET','YOUR_SECRET_HERE');
|
||||
// Create your application here: https://developer.spotify.com/my-applications
|
||||
define('CLIENT_ID','YOUR_CLIENT_ID_HERE');
|
||||
define('CLIENT_SECRET','YOUR_CLIENT_SECRET_HERE');
|
||||
define('REDIRECT_URI','YOUR_REDIRECT_URI_HERE');
|
||||
|
||||
// Allow cross-domain requests
|
||||
@ -177,3 +170,4 @@ function refreshToken($refresh_token){
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -111,7 +111,7 @@ export let digestMopidyImages = function(mopidy, images){
|
||||
images[i].url = url
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user