This commit is contained in:
2022-06-13 23:37:17 +08:00
parent d21608a860
commit 0230cb42a2
153 changed files with 62907 additions and 0 deletions

28
oauth2/auth.php Normal file
View File

@@ -0,0 +1,28 @@
<?php
require_once __DIR__.'/server.php';
$request = OAuth2\Request::createFromGlobals();
$response = new OAuth2\Response();
if (!$server->validateAuthorizeRequest($request, $response)) {
$code = array(
"code"=>400,
"msg"=>$response->getParameter("error_description")
);
die(json_encode($code,JSON_UNESCAPED_UNICODE));
}
if (empty($_POST)) {
$scopes=$_GET['scope'];
if (empty($scopes)){
$code = array(
"code"=>401,
"msg"=>"权限点信息scope不应为空"
);
die(json_encode($code,JSON_UNESCAPED_UNICODE));
}
include ROOT.'page/oauth2/auth.php';
die();
}
// print the authorization code if the user has authorized your client
$is_authorized = ($_POST['authorized'] === 'yes');
$server->handleAuthorizeRequest($request, $response, $is_authorized,$cookie::get('uid'));
$response->send();

9
oauth2/res.php Normal file
View File

@@ -0,0 +1,9 @@
<?php
// include our OAuth2 Server object
require_once __DIR__.'/server.php';
// Handle a request for an OAuth2.0 Access Token and send the response to the client
if (!$server->verifyResourceRequest(OAuth2\Request::createFromGlobals())) {
$server->getResponse()->send();
die;
}
print_r($server);

13
oauth2/server.php Normal file
View File

@@ -0,0 +1,13 @@
<?php
include '../includes/common.php';
/** 配置 */
$storage = new OAuth2\Storage\Pdo(array('dsn' => 'mysql:dbname='.$dbconfig['dbname'].';host='.$dbconfig['host'], 'username' => $dbconfig['user'], 'password' => $dbconfig['pwd']));
// 通过存储对象或对象数组存储的oauth2服务器类
$server = new OAuth2\Server($storage);
// 授权码 有效期只有30秒
$server->addGrantType(new OAuth2\GrantType\AuthorizationCode($storage));
// 客户端证书
$server->addGrantType(new OAuth2\GrantType\ClientCredentials($storage));
// 用户凭据
$server->addGrantType(new OAuth2\GrantType\UserCredentials($storage));

6
oauth2/token.php Normal file
View File

@@ -0,0 +1,6 @@
<?php
// include our OAuth2 Server object
require_once __DIR__.'/server.php';
// Handle a request for an OAuth2.0 Access Token and send the response to the client
$server->handleTokenRequest(OAuth2\Request::createFromGlobals())->send();