Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
jnsga authored and quitte committed Feb 23, 2024
0 parents commit 32d483a
Show file tree
Hide file tree
Showing 7 changed files with 905 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vendor/
providerConfig.php
37 changes: 37 additions & 0 deletions callback.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
#error_reporting(E_ALL);
#ini_set('display_errors', 1);


session_start();

$provider = require 'providerConfig.php';

try {
if (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {
unset($_SESSION['oauth2state']);
throw new Exception('Invalid state');
}

$token = $provider->getAccessToken('authorization_code', [
'code' => $_GET['code']
]);

$resourceOwner = $provider->getResourceOwner($token);
$userData = $resourceOwner->toArray();


// Save user data and token in session or database here
$_SESSION['user'] = $userData["name"];
$_SESSION['token'] = $token->getToken();

// Redirect to index.php
header('Location: index.php');
exit();

} catch (Exception $e) {
// Log the error message and display a generic error message to the user
error_log($e->getMessage());
echo '<p>An error occurred during the login process. Please try again.</p>';
echo '<p><a href="index.php">Try again</a></p>';
}
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require": {
"league/oauth2-client": "^2.7"
}
}
Loading

0 comments on commit 32d483a

Please sign in to comment.