2020-05-16 23:27:06 +00:00
|
|
|
<?php
|
2021-04-05 08:43:30 +00:00
|
|
|
//https://developers.google.com/oauthplayground/
|
|
|
|
//https://developer.okta.com/blog/2018/04/10/oauth-authorization-code-grant-type
|
|
|
|
|
|
|
|
class Oauth
|
2020-05-16 23:27:06 +00:00
|
|
|
{
|
2021-04-05 08:43:30 +00:00
|
|
|
function default()
|
2020-05-16 23:27:06 +00:00
|
|
|
{
|
2021-04-05 08:43:30 +00:00
|
|
|
//Log
|
|
|
|
$logManager = new LogManager(__DIR__ . '/../../logs/auth/' . date("Y-m-d") . '.log');
|
|
|
|
$logManager->setLevel(LOGLEVEL);
|
2021-04-11 08:40:32 +00:00
|
|
|
$logManager->write("[OAUTH] GET " . json_encode($_GET), LogRecordTypes::WARNING);
|
|
|
|
$logManager->write("[OAUTH] DATA " . file_get_contents('php://input'), LogRecordTypes::WARNING);
|
|
|
|
$logManager->write("[OAUTH] URL " . $_SERVER['REQUEST_URI'], LogRecordTypes::WARNING);
|
2021-04-05 08:43:30 +00:00
|
|
|
|
|
|
|
$userManager = new UserManager();
|
2020-07-23 13:16:44 +00:00
|
|
|
$langMng = new LanguageManager('en');
|
2020-05-16 23:27:06 +00:00
|
|
|
|
|
|
|
$template = new Template('oauth');
|
|
|
|
$template->prepare('baseDir', BASEDIR);
|
2020-12-09 11:19:19 +00:00
|
|
|
$template->prepare('baseUrl', BASEURL);
|
2020-05-17 12:24:56 +00:00
|
|
|
$template->prepare('title', 'Simple Home - Oauth');
|
2020-05-16 23:27:06 +00:00
|
|
|
|
2021-04-05 08:43:30 +00:00
|
|
|
if (isset($_GET['response_type']) && $_GET['response_type'] == 'code') {
|
2020-05-16 23:27:06 +00:00
|
|
|
$template->prepare('responseType', $_GET['response_type']);
|
|
|
|
$template->prepare('redirectUrl', $_GET['redirect_uri']);
|
|
|
|
$template->prepare('clientId', $_GET['client_id']);
|
2021-04-05 08:43:30 +00:00
|
|
|
$template->prepare('scope', $_GET['scope']);
|
2020-05-16 23:27:06 +00:00
|
|
|
$template->prepare('state', $_GET['state']);
|
|
|
|
} else {
|
2021-04-05 08:43:30 +00:00
|
|
|
if (isset($_GET['redirect_uri'])) {
|
|
|
|
$template->prepare('responseType', $_GET['response_type']);
|
|
|
|
$template->prepare('redirectUrl', $_GET['redirect_uri']);
|
|
|
|
$template->prepare('clientId', $_GET['client_id']);
|
|
|
|
$template->prepare('state', $_GET['state']);
|
|
|
|
} else {
|
|
|
|
$template->prepare('responseType', $_POST['responseType']);
|
|
|
|
$template->prepare('redirectUrl', $_POST['redirectUrl']);
|
|
|
|
$template->prepare('clientId', $_POST['clientId']);
|
|
|
|
$template->prepare('state', $_POST['state']);
|
|
|
|
}
|
2020-05-16 23:27:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$template->render();
|
|
|
|
}
|
2021-04-05 08:43:30 +00:00
|
|
|
|
|
|
|
function token()
|
|
|
|
{
|
|
|
|
//Log
|
|
|
|
$logManager = new LogManager(__DIR__ . '/../../logs/auth/' . date("Y-m-d") . '.log');
|
|
|
|
$logManager->setLevel(LOGLEVEL);
|
2021-04-11 08:40:32 +00:00
|
|
|
$logManager->write("[OAUTH] GET " . json_encode($_GET), LogRecordTypes::WARNING);
|
|
|
|
$logManager->write("[OAUTH] POST " . json_encode($_POST), LogRecordTypes::WARNING);
|
|
|
|
$logManager->write("[OAUTH] DATA " . file_get_contents('php://input'), LogRecordTypes::WARNING);
|
|
|
|
$logManager->write("[OAUTH] URL " . $_SERVER['REQUEST_URI'], LogRecordTypes::WARNING);
|
2021-04-05 08:43:30 +00:00
|
|
|
|
|
|
|
// $template = new Template('oauth');
|
|
|
|
// $template->prepare('baseDir', BASEDIR);
|
|
|
|
// $template->prepare('baseUrl', BASEURL);
|
|
|
|
// $template->prepare('title', 'Simple Home - Oauth');
|
|
|
|
// $template->render();
|
|
|
|
|
|
|
|
$token = $_POST["code"];
|
|
|
|
$get = [
|
|
|
|
"access_token" => $token,
|
2021-04-11 08:40:32 +00:00
|
|
|
"token_type" => "Bearer",
|
2021-04-05 08:43:30 +00:00
|
|
|
"refresh_token" => $token,
|
|
|
|
"scope" => 'user',
|
2021-04-11 08:40:32 +00:00
|
|
|
//"expires_in" => 63113851,
|
2021-04-05 08:43:30 +00:00
|
|
|
];
|
|
|
|
|
2021-04-11 08:40:32 +00:00
|
|
|
$logManager->write("[OAUTH] Response " . json_encode($get), LogRecordTypes::WARNING);
|
2021-04-05 08:43:30 +00:00
|
|
|
echo json_encode($get);
|
|
|
|
die();
|
|
|
|
}
|
2020-05-16 23:27:06 +00:00
|
|
|
}
|