-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexchange-code.php
More file actions
59 lines (47 loc) · 1.75 KB
/
exchange-code.php
File metadata and controls
59 lines (47 loc) · 1.75 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
<?php
// Manually exchange authorization code for tokens
$config = require('config.php');
// The code you received
$code = '89b7b84d27c476cef55f1dd526ab23f2';
$clientId = $config['xapi']['admin']['clientId'];
$clientSecret = $config['xapi']['admin']['clientSecret'];
// Try different redirect URIs since ALM sent it to root
$redirectUris = [
'https://p0qp0q.com/',
'https://p0qp0q.com/alm-kawaii-quiz/oauth-callback.php',
'https://p0qp0q.com'
];
foreach ($redirectUris as $redirectUri) {
echo "Trying with redirect URI: $redirectUri\n\n";
$tokenUrl = 'https://learningmanager.adobe.com/oauth/token';
$postData = [
'code' => $code,
'client_id' => $clientId,
'client_secret' => $clientSecret,
'redirect_uri' => $redirectUri,
'grant_type' => 'authorization_code'
];
$ch = curl_init($tokenUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/x-www-form-urlencoded'
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo "HTTP Code: $httpCode\n";
echo "Response: $response\n\n";
if ($httpCode === 200) {
$tokens = json_decode($response, true);
echo "✅ SUCCESS! Got tokens:\n\n";
echo "Refresh Token: " . $tokens['refresh_token'] . "\n\n";
echo "Access Token: " . $tokens['access_token'] . "\n\n";
echo "Add this to your config.php:\n";
echo "'refreshToken' => '" . $tokens['refresh_token'] . "',\n\n";
break;
}
echo "-------------------\n\n";
}
?>