<?php
namespace OAuth2;
use OAuth2\Controller\ResourceControllerInterface;
use OAuth2\Controller\ResourceController;
use OAuth2\OpenID\Controller\UserInfoControllerInterface;
use OAuth2\OpenID\Controller\UserInfoController;
use OAuth2\OpenID\Controller\AuthorizeController as OpenIDAuthorizeController;
use OAuth2\OpenID\ResponseType\AuthorizationCode as OpenIDAuthorizationCodeResponseType;
use OAuth2\OpenID\Storage\AuthorizationCodeInterface as OpenIDAuthorizationCodeInterface;
use OAuth2\OpenID\GrantType\AuthorizationCode as OpenIDAuthorizationCodeGrantType;
use OAuth2\Controller\AuthorizeControllerInterface;
use OAuth2\Controller\AuthorizeController;
use OAuth2\Controller\TokenControllerInterface;
use OAuth2\Controller\TokenController;
use OAuth2\ClientAssertionType\ClientAssertionTypeInterface;
use OAuth2\ClientAssertionType\HttpBasic;
use OAuth2\ResponseType\ResponseTypeInterface;
use OAuth2\ResponseType\AuthorizationCode as AuthorizationCodeResponseType;
use OAuth2\ResponseType\AccessToken;
use OAuth2\ResponseType\JwtAccessToken;
use OAuth2\OpenID\ResponseType\CodeIdToken;
use OAuth2\OpenID\ResponseType\IdToken;
use OAuth2\OpenID\ResponseType\IdTokenToken;
use OAuth2\TokenType\TokenTypeInterface;
use OAuth2\TokenType\Bearer;
use OAuth2\GrantType\GrantTypeInterface;
use OAuth2\GrantType\UserCredentials;
use OAuth2\GrantType\ClientCredentials;
use OAuth2\GrantType\RefreshToken;
use OAuth2\GrantType\AuthorizationCode;
use OAuth2\Storage\ClientCredentialsInterface;
use OAuth2\Storage\ClientInterface;
use OAuth2\Storage\JwtAccessToken as JwtAccessTokenStorage;
use OAuth2\Storage\JwtAccessTokenInterface;
use InvalidArgumentException;
use LogicException;
/**
* Server class for OAuth2
* This class serves as a convience class which wraps the other Controller classes
*
* @see \OAuth2\Controller\ResourceController
* @see \OAuth2\Controller\AuthorizeController
* @see \OAuth2\Controller\TokenController
*/
class Server implements ResourceControllerInterface,
AuthorizeControllerInterface,
TokenControllerInterface,
UserInfoControllerInterface
{
/**
* @var ResponseInterface
*/
protected $response;
/**
* @var array
*/
protected $config;
/**
* @var array
*/
protected $storages;
/**
* @var AuthorizeControllerInterface
*/
protected $authorizeController;
/**
* @var TokenControllerInterface
*/
protected $tokenController;
/**
* @var ResourceControllerInterface
*/
protected $resourceController;
/**
* @var UserInfoControllerInterface
*/
protected $userInfoController;
/**
* @var array
*/
protected $grantTypes = array();
/**
* @var array
*/
protected $responseTypes = array();
/**
* @var TokenTypeInterface
*/
protected $tokenType;
/**
* @var ScopeInterface
*/
protected $scopeUtil;
/**
* @var ClientAssertionTypeInterface
*/
protected $clientAssertionType;
/**
* @var array
*/
protected $storageMap = array(
'access_token' => 'OAuth2\Storage\AccessTokenInterface',
'authorization_code' => 'OAuth2\Storage\AuthorizationCodeInterface',
'client_credentials' => 'OAuth2\Storage\ClientCredentialsInterface',
'client' => 'OAuth2\Storage\ClientInterface',
'refresh_token' => 'OAuth2\Storage\RefreshTokenInterface',
'user_credentials' => 'OAuth2\Storage\UserCredentialsInterface',
'user_claims' => 'OAuth2\OpenID\Storage\UserClaimsInterface',
'public_key' => 'OAuth2\Storage\PublicKeyInterface',
'jwt_bearer' => 'OAuth2\Storage\JWTBearerInterface',
'scope' => 'OAuth2\Storage\ScopeInterface',
);
/**
* @var array
*/
protected $responseTypeMap = array(
'token' => 'OAuth2\ResponseType\AccessTokenInterface',
'code' => 'OAuth2\ResponseType\AuthorizationCodeInterface',
'id_token' => 'OAuth2\OpenID\ResponseType\IdTokenInterface',
'id_token token' => 'OAuth2\OpenID\ResponseType\IdTokenTokenInterface',
'code id_token' => 'OAuth2\OpenID\ResponseType\CodeIdTokenInterface',
);
/**
* @param mixed $storage (array or OAuth2\Storage) - single object or array of objects implementing the
* required storage types (ClientCredentialsInterface and AccessTokenInterface as a minimum)
* @param array $config specify a different token lifetime, token header name, etc
* @param array $grantTypes An array of OAuth2\GrantType\GrantTypeInterface to use for granting access tokens
* @param array $responseTypes Response types to use. array keys should be "code" and "token" for
* Access Token and Authorization Code response types
* @param TokenTypeInterface $tokenType The token type object to use. Valid token types are "bearer" and "mac"
* @param ScopeInterface $scopeUtil The scope utility class to use to validate scope
* @param ClientAssertionTypeInterface $clientAssertionType The method in which to verify the client identity. Default is HttpBasic
*
* @ingroup oauth2_section_7
*/
public function __construct($storage = array(), array $config = array(), array $grantTypes = array(), array $responseTypes = array(), TokenTypeInterface $tokenType = null, ScopeInterface $scopeUtil = null, ClientAssertionTypeInterface $clientAssertionType = null)
{
$storage = is_array($storage) ? $storage : array($storage);
$this->storages = array();
foreach ($storage as $key => $service) {
$this->addStorage($service, $key);
}
// merge all config values. These get passed to our controller objects
$this->config = array_merge(array(
'use_jwt_access_tokens' => false,
'jwt_extra_payload_callable' => null,
'store_encrypted_token_string' => true,
'use_openid_connect' => false,
'id_lifetime' => 3600,
'access_lifetime' => 3600,
'www_realm' => 'Service',
'token_param_name' => 'access_token',
'token_bearer_header_name' => 'Bearer',
'enforce_state' => true,
'require_exact_redirect_uri' => false,
'allow_implicit' => false,
'allow_credentials_in_request_body' => true,
'allow_public_clients' => true,
'always_issue_new_refresh_token' => false,
'unset_refresh_token_after_use' => true,
), $config);
foreach ($grantTypes as $key => $grantType) {
$this->addGrantType($grantType, $key);
}
foreach ($responseTypes as $key => $responseType) {
$this->addResponseType($responseType, $key);
}
$this->tokenType = $tokenType;
$this->scopeUtil = $scopeUtil;
$this->clientAssertionType = $clientAssertionType;
if ($this->config['use_openid_connect']) {
$this->validateOpenIdConnect();
}
}
/**
* @return AuthorizeControllerInterface
*/
public function getAuthorizeController()
{
if (is_null($this->authorizeController)) {
$this->authorizeController = $this->createDefaultAuthorizeController();
}
return $this->authorizeController;
}
/**
* @return TokenController
*/
public function getTokenController()
{
if (is_null($this->tokenController)) {
$this->tokenController = $this->createDefaultTokenController();
}
return $this->tokenController;
}
/**
* @return
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
全面认识第三方授权机制 oauth2.0 协议,如何在 php 上搭建 oauth2.0服务端!对应博文如下:https://blog.csdn.net/xh870189248/article/details/85126364
资源推荐
资源详情
资源评论
收起资源包目录
ZMD.zip (80个子文件)
ZMD
getResource.php 1KB
AligenieToken.php 1KB
index.html 495B
.idea
webServers.xml 568B
misc.xml 4KB
workspace.xml 18KB
ZMD.iml 288B
inspectionProfiles
deployment.xml 507B
modules.xml 265B
codeStyles
Project.xml 2KB
404.html 479B
OAuth2
ClientAssertionType
HttpBasic.php 5KB
ClientAssertionTypeInterface.php 566B
Response.php 12KB
TokenType
TokenTypeInterface.php 433B
Bearer.php 5KB
Mac.php 410B
Server.php 37KB
ScopeInterface.php 1KB
Storage
JwtAccessTokenInterface.php 272B
MongoDB.php 12KB
DynamoDB.php 17KB
ClientInterface.php 2KB
PublicKeyInterface.php 612B
UserCredentialsInterface.php 2KB
Memory.php 11KB
Pdo.php 25KB
ClientCredentialsInterface.php 1KB
ScopeInterface.php 1KB
Cassandra.php 18KB
Redis.php 9KB
AccessTokenInterface.php 2KB
JwtAccessToken.php 3KB
RefreshTokenInterface.php 3KB
Mongo.php 12KB
CouchbaseDB.php 10KB
AuthorizationCodeInterface.php 3KB
JwtBearerInterface.php 2KB
GrantType
AuthorizationCode.php 4KB
UserCredentials.php 3KB
RefreshToken.php 5KB
JwtBearer.php 8KB
ClientCredentials.php 2KB
GrantTypeInterface.php 1KB
Controller
AuthorizeControllerInterface.php 2KB
TokenController.php 12KB
TokenControllerInterface.php 1KB
ResourceControllerInterface.php 1KB
ResourceController.php 5KB
AuthorizeController.php 17KB
Scope.php 3KB
Autoloader.php 1KB
ResponseType
AuthorizationCode.php 3KB
AccessToken.php 8KB
AccessTokenInterface.php 1KB
JwtAccessToken.php 6KB
AuthorizationCodeInterface.php 1KB
ResponseTypeInterface.php 237B
OpenID
Storage
UserClaimsInterface.php 1KB
AuthorizationCodeInterface.php 2KB
GrantType
AuthorizationCode.php 1KB
Controller
UserInfoController.php 2KB
AuthorizeControllerInterface.php 253B
UserInfoControllerInterface.php 726B
AuthorizeController.php 4KB
ResponseType
AuthorizationCode.php 2KB
IdToken.php 5KB
IdTokenInterface.php 1KB
IdTokenTokenInterface.php 160B
CodeIdTokenInterface.php 159B
CodeIdToken.php 991B
AuthorizationCodeInterface.php 1KB
IdTokenToken.php 1KB
ResponseInterface.php 1KB
Encryption
Jwt.php 6KB
FirebaseJwt.php 1KB
EncryptionInterface.php 620B
RequestInterface.php 728B
Request.php 9KB
AligenieAuthorize.php 3KB
共 80 条
- 1
资源评论
- uk12852019-01-15调试不成功,获取不了TOKEN。调了两天都不行
- lan_ye_er2019-07-12不是很好用,参考用吧
半颗心脏
- 粉丝: 1w+
- 资源: 48
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功