Initial Commit
This commit is contained in:
48
cb.php
Normal file
48
cb.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
if (!isset($_GET['code'])) {
|
||||
die("No code provided.");
|
||||
}
|
||||
|
||||
$code = $_GET['code'];
|
||||
$client_id = 'your_client_id';
|
||||
$client_secret = 'your_client_secret';
|
||||
$redirect_uri = 'the_full_callback_url_of_this_script.php';
|
||||
|
||||
$token = null;
|
||||
$user = null;
|
||||
|
||||
// Exchange code for token
|
||||
$ch = curl_init('https://surillya.com/auth/token.php');
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
|
||||
'client_id' => $client_id,
|
||||
'client_secret' => $client_secret,
|
||||
'code' => $code
|
||||
]));
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$response = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
$data = json_decode($response, true);
|
||||
if (isset($data['access_token'])) {
|
||||
$_SESSION['access_token'] = $data['access_token'];
|
||||
|
||||
setcookie("access_token", $data['access_token'], time() + 7*24*60*60, "/", "", true, true);
|
||||
|
||||
header("Location: profile.php");
|
||||
exit;
|
||||
} else {
|
||||
echo "Failed to log in!";
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head><title>Welcome!</title></head>
|
||||
<body>
|
||||
<?php if ($user): ?>
|
||||
<h1>Logged in as <?= htmlspecialchars($user['name']) ?> (<?= htmlspecialchars($user['email']) ?>)</h1>
|
||||
<?php else: ?>
|
||||
<p>Something went wrong logging you in :(</p>
|
||||
<?php endif; ?>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user