2 Star 9 Fork 3

ok_fish/oauth2.0_demo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
authorize.php 1.42 KB
一键复制 编辑 原始数据 按行查看 历史
ok_fish 提交于 2018-01-20 14:54 . add readme
<?php
/***
* 授权页面
*/
// include our OAuth2 Server object
require_once __DIR__.'/server.php';
$request = OAuth2\Request::createFromGlobals();
$response = new OAuth2\Response();
// validate the authorize request
if (!$server->validateAuthorizeRequest($request, $response)) {
$response->send();
die;
}
// display an authorization form
if (empty($_POST)) {
exit('
<form method="post">
<label>授权TestClient?</label><br />
<p><span>账号:</span><input type="text" name="username" value=""></p>
<p><span>密码:</span><input type="password" name="password" value="" /></p>
<input type="submit" name="authorized" value="yes">
<input type="submit" name="authorized" value="no">
</form>');
}
// print the authorization code if the user has authorized your client
$is_authorized = ($_POST['authorized'] === 'yes');
//todo::账号密码 对应的需要切换到平台的账号 去做验证 这里固定值
$user_id = '1234';
$server->handleAuthorizeRequest($request, $response, $is_authorized,$user_id);
if ($is_authorized) {
// this is only here so that you get to see your code in the cURL request. Otherwise, we'd redirect back to the client
$code = substr($response->getHttpHeader('Location'), strpos($response->getHttpHeader('Location'), 'code=')+5, 40);
$response->setRedirect(302,$_GET['redirect_uri'].'?code='.$code."&state=".$_GET['state']);
//exit("SUCCESS! Authorization Code: $code");
}
$response->send();
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/hepanming007/oauth2.0_demo.git
git@gitee.com:hepanming007/oauth2.0_demo.git
hepanming007
oauth2.0_demo
oauth2.0_demo
master

搜索帮助