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>
|
40
index.php
Normal file
40
index.php
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Login with Surillya</title>
|
||||||
|
<script src="https://cdn.tailwindcss.com"></script>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background: #1a1a2e;
|
||||||
|
}
|
||||||
|
.sparkle:hover {
|
||||||
|
animation: sparkle 0.8s infinite;
|
||||||
|
}
|
||||||
|
@keyframes sparkle {
|
||||||
|
0% { filter: brightness(1); }
|
||||||
|
50% { filter: brightness(1.4); }
|
||||||
|
100% { filter: brightness(1); }
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body class="flex items-center justify-center min-h-screen text-white">
|
||||||
|
<div class="bg-[#2d2d44] p-10 rounded-2xl shadow-2xl w-full max-w-md text-center">
|
||||||
|
<h1 class="text-3xl font-bold text-pink-300 mb-6">Welcome to CoolClient</h1>
|
||||||
|
<p class="mb-4 text-gray-300">Login using your Surillya account</p>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
$client_id = 'your_client_id';
|
||||||
|
$redirect_uri = urlencode('your_full_callback_script_url.php');
|
||||||
|
$auth_url = "https://surillya.com/auth/authorize.php?response_type=code&client_id=$client_id&redirect_uri=$redirect_uri";
|
||||||
|
?>
|
||||||
|
|
||||||
|
<a href="<?= $auth_url ?>">
|
||||||
|
<button class="sparkle bg-gradient-to-r from-pink-400 via-blue-400 to-orange-300 text-black font-semibold px-6 py-3 rounded-xl shadow-lg hover:scale-105 transition-all">
|
||||||
|
<span class="mr-2">✨</span> Login with Surillya
|
||||||
|
</button>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
9
logout.php
Normal file
9
logout.php
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
session_destroy();
|
||||||
|
|
||||||
|
// Clear cookie too
|
||||||
|
setcookie("access_token", "", time() - 3600, "/", "", true, true);
|
||||||
|
|
||||||
|
header("Location: index.php");
|
||||||
|
exit;
|
35
profile.php
Normal file
35
profile.php
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
$token = $_SESSION['access_token'] ?? $_COOKIE['access_token'] ?? null;
|
||||||
|
|
||||||
|
if (!$token) {
|
||||||
|
header("Location: index.php");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get user info
|
||||||
|
$ch = curl_init('https://surillya.com/auth/userinfo.php');
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||||
|
"Authorization: Bearer $token"
|
||||||
|
]);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
$user_response = curl_exec($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
$user = json_decode($user_response, true);
|
||||||
|
|
||||||
|
if (!$user) {
|
||||||
|
echo "Invalid token or failed to fetch user.";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head><title>Welcome, <?= htmlspecialchars($user['name']) ?>!</title></head>
|
||||||
|
<body>
|
||||||
|
<h1>Hello, <?= htmlspecialchars($user['name']) ?>!</h1>
|
||||||
|
<p>Email: <?= htmlspecialchars($user['email']) ?></p>
|
||||||
|
<a href="logout.php"><button>Log out</button></a>
|
||||||
|
</body>
|
||||||
|
</html>
|
Reference in New Issue
Block a user