Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent exposing the API key #1

Open
mwllgr opened this issue Dec 6, 2021 · 0 comments
Open

Prevent exposing the API key #1

mwllgr opened this issue Dec 6, 2021 · 0 comments

Comments

@mwllgr
Copy link

mwllgr commented Dec 6, 2021

Hi, maybe a seperate file for recent tracks requesting would be a nice idea. This way, the API key isn't leaked to the public via the HTTP request.

For example, just by creating a seperate file (recents.php) with this content:

<?php 
$user     = 'xxxxxxx';
$key      = 'xxxxxxx';
$status   = 'Last Played';
$endpoint = 'https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=' . $user . '&limit=2&api_key=' . $key . '&format=json';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); // 0 for indefinite
curl_setopt($ch, CURLOPT_TIMEOUT, 10); // 10 second attempt before timing out
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
$response = curl_exec($ch);
$lastfm[] = json_decode($response, true);
curl_close($ch);

header('Content-Type: application/json; charset=utf-8');
echo $response;

One could then replace the link in the requestUpdate() JavaScript function.
I think this would be a nice addition to this really cool project!

@mwllgr mwllgr changed the title Preventing exposing of API key Preventing exposing the API key Dec 6, 2021
@mwllgr mwllgr changed the title Preventing exposing the API key Prevent exposing the API key Jan 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant