From 5abb9c775afee60f3804fdd2117fd7a9ae1f1140 Mon Sep 17 00:00:00 2001 From: James Barnsley Date: Thu, 2 Nov 2017 20:51:19 +1300 Subject: [PATCH] Authorization for LastFM --- build_tools/auth_lastfm.php | 154 +++++++++++++++++++++ build_tools/{auth.php => auth_spotify.php} | 0 2 files changed, 154 insertions(+) create mode 100755 build_tools/auth_lastfm.php rename build_tools/{auth.php => auth_spotify.php} (100%) diff --git a/build_tools/auth_lastfm.php b/build_tools/auth_lastfm.php new file mode 100755 index 00000000..ec5b814b --- /dev/null +++ b/build_tools/auth_lastfm.php @@ -0,0 +1,154 @@ + + + "auth.getSession", + "token" => $token + ), + false + ); + + curl_setopt($ch, CURLOPT_URL,API_URL); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); + curl_setopt($ch, CURLINFO_HEADER_OUT, true); + curl_setopt($ch, CURLOPT_VERBOSE, true); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + + $response = curl_exec($ch); + + if (curl_errno($ch)){ + echo 'CURL Error: '. curl_error($ch); + } + curl_close($ch); + + $response = json_decode($response, true); + + // Append our other important values to successful signings + if (!$response['error']){ + $response['api_key'] = API_KEY; + } + + return $response; +} + + +/** + * Perform a signed request + * + * @param $data = array + * @param $post = boolean (POST request) + **/ +function signRequest($data = array(), $post = 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); + + // Loop all the values in our request and add to our signature + $signature = ""; + ksort($request); + foreach ($request as $key => $value){ + $signature.= $key.$value; + } + + // Finalize the signature + $signature.= API_SECRET; + $signature = md5($signature); + $request["api_sig"] = $signature; + + return $request; +} diff --git a/build_tools/auth.php b/build_tools/auth_spotify.php similarity index 100% rename from build_tools/auth.php rename to build_tools/auth_spotify.php