-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallback.php
More file actions
66 lines (54 loc) · 1.9 KB
/
callback.php
File metadata and controls
66 lines (54 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
* Spotify Api module for xoops
*
* @package spotifyapi
* @subpackage page-level
* @author Squiz Pty Ltd <products@squiz.net>
* @copyright 2023 Michael Albertsen (www.culex.dk)
* @since 1.0
* @min_xoops 2.5.9
*/
use XoopsModules\Spotifyapi\{Spotifyapi_Helper};
require_once dirname(__DIR__, 2) . '/mainfile.php';
include __DIR__ . '/preloads/autoloader.php';
require_once __DIR__ . '/include/common.php';
require_once XOOPS_ROOT_PATH . '/class/template.php';
$helper = Spotifyapi_Helper::getInstance();
$GLOBALS['xoopsLogger']->activated = false;
$block = [];
$clientid = $helper->getConfig('spotifyapiclientid');
$clientsecret = $helper->getConfig('spotifyapiclientsecret');
$clientredirecturi = $helper->getConfig('spotifyapiredirecturi');
$db = new XoopsModules\Spotifyapi\Spotifyapi_db();
$session = new XoopsModules\Spotifyapi\Spotifyapi_Session(
$clientid,
$clientsecret,
$clientredirecturi
);
$state = $_GET['state'];
// Fetch the stored state value from somewhere. A session for example
$storedState = $_SESSION['state'];
if ($state !== $storedState) {
// The state returned isn't the same as the one we've stored, we shouldn't continue
die('State mismatch');
}
// Request an access token using the code from Spotify
try {
$session->requestAccessToken($_GET['code']);
} catch (\XoopsModules\Spotifyapi\SpotifyWebAPIAuthException $e) {
} catch (\XoopsModules\Spotifyapi\SpotifyWebAPIException $e) {
}
$db->code = $_GET['code'];
$db->setConfig('code');
$accessToken = $session->getAccessToken();
$refreshToken = $session->getRefreshToken();
// Store the access and refresh tokens somewhere. In a session for example
$db->accessToken = $accessToken;
$db->refreshToken = $refreshToken;
$db->setConfig('accessToken');
$db->setConfig('refreshToken');
// Send the user along and fetch some data!
header("Content-type: application/javascript");
header('Location: app.php');
die();