Server
Server class for OAuth2 This class serves as a convience class which wraps the other Controller classes
- Full name:
\OAuth2\Server
- This class implements:
\OAuth2\Controller\ResourceControllerInterface
,\OAuth2\Controller\AuthorizeControllerInterface
,\OAuth2\Controller\TokenControllerInterface
,\OAuth2\OpenID\Controller\UserInfoControllerInterface
See Also:
- \OAuth2\Controller\ResourceController -
- \OAuth2\Controller\AuthorizeController -
- \OAuth2\Controller\TokenController -
Properties
response
config
storages
authorizeController
tokenController
resourceController
userInfoController
grantTypes
responseTypes
tokenType
scopeUtil
clientAssertionType
storageMap
responseTypeMap
Methods
__construct
public __construct(mixed $storage = array(), array $config = array(), array $grantTypes = array(), array $responseTypes = array(), \OAuth2\TokenType\TokenTypeInterface $tokenType = null, \OAuth2\ScopeInterface $scopeUtil = null, \OAuth2\ClientAssertionType\ClientAssertionTypeInterface $clientAssertionType = null): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$storage |
mixed | (array or OAuth2\Storage) - single object or array of objects implementing the required storage types (ClientCredentialsInterface and AccessTokenInterface as a minimum) |
$config |
array | specify a different token lifetime, token header name, etc |
$grantTypes |
array | An array of OAuth2\GrantType\GrantTypeInterface to use for granting access tokens |
$responseTypes |
array | Response types to use. array keys should be "code" and "token" for Access Token and Authorization Code response types |
$tokenType |
\OAuth2\TokenType\TokenTypeInterface | The token type object to use. Valid token types are "bearer" and "mac" |
$scopeUtil |
\OAuth2\ScopeInterface | The scope utility class to use to validate scope |
$clientAssertionType |
\OAuth2\ClientAssertionType\ClientAssertionTypeInterface | The method in which to verify the client identity. Default is HttpBasic |
getAuthorizeController
getTokenController
getResourceController
getUserInfoController
setAuthorizeController
public setAuthorizeController(\OAuth2\Controller\AuthorizeControllerInterface $authorizeController): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$authorizeController |
\OAuth2\Controller\AuthorizeControllerInterface |
setTokenController
Parameters:
Parameter | Type | Description |
---|---|---|
$tokenController |
\OAuth2\Controller\TokenControllerInterface |
setResourceController
public setResourceController(\OAuth2\Controller\ResourceControllerInterface $resourceController): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$resourceController |
\OAuth2\Controller\ResourceControllerInterface |
setUserInfoController
public setUserInfoController(\OAuth2\OpenID\Controller\UserInfoControllerInterface $userInfoController): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$userInfoController |
\OAuth2\OpenID\Controller\UserInfoControllerInterface |
handleUserInfoRequest
Return claims about the authenticated end-user.
public handleUserInfoRequest(\OAuth2\RequestInterface $request, \OAuth2\ResponseInterface $response = null): \OAuth2\ResponseInterface
This would be called from the "/UserInfo" endpoint as defined in the spec.
Parameters:
Parameter | Type | Description |
---|---|---|
$request |
\OAuth2\RequestInterface | - Request object to grant access token |
$response |
\OAuth2\ResponseInterface | - Response object containing error messages (failure) or user claims (success) |
Throws:
See Also:
- http://openid.net/specs/openid-connect-core-1_0.html#UserInfo -
handleTokenRequest
Grant or deny a requested access token.
public handleTokenRequest(\OAuth2\RequestInterface $request, \OAuth2\ResponseInterface $response = null): \OAuth2\ResponseInterface
This would be called from the "/token" endpoint as defined in the spec. Obviously, you can call your endpoint whatever you want.
Parameters:
Parameter | Type | Description |
---|---|---|
$request |
\OAuth2\RequestInterface | - Request object to grant access token |
$response |
\OAuth2\ResponseInterface | - Response object containing error messages (failure) or access token (success) |
Throws:
See Also:
- http://tools.ietf.org/html/rfc6749#section-4 - * http://tools.ietf.org/html/rfc6749#section-10.6 - * http://tools.ietf.org/html/rfc6749#section-4.1.3 -
grantAccessToken
Grant or deny a requested access token.
public grantAccessToken(\OAuth2\RequestInterface $request, \OAuth2\ResponseInterface $response = null): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$request |
\OAuth2\RequestInterface | - Request object to grant access token |
$response |
\OAuth2\ResponseInterface | - Response object |
handleRevokeRequest
Handle a revoke token request This would be called from the "/revoke" endpoint as defined in the draft Token Revocation spec
public handleRevokeRequest(\OAuth2\RequestInterface $request, \OAuth2\ResponseInterface $response = null): \OAuth2\Response|\OAuth2\ResponseInterface
Parameters:
Parameter | Type | Description |
---|---|---|
$request |
\OAuth2\RequestInterface | |
$response |
\OAuth2\ResponseInterface |
See Also:
- https://tools.ietf.org/html/rfc7009#section-2 -
handleAuthorizeRequest
Redirect the user appropriately after approval.
public handleAuthorizeRequest(\OAuth2\RequestInterface $request, \OAuth2\ResponseInterface $response, bool $is_authorized, mixed $user_id = null): \OAuth2\ResponseInterface
After the user has approved or denied the resource request the authorization server should call this function to redirect the user appropriately.
Parameters:
Parameter | Type | Description |
---|---|---|
$request |
\OAuth2\RequestInterface | - The request should have the follow parameters set in the querystring: - response_type: The requested response: an access token, an authorization code, or both. - client_id: The client identifier as described in Section 2. - redirect_uri: An absolute URI to which the authorization server will redirect the user-agent to when the end-user authorization step is completed. - scope: (optional) The scope of the resource request expressed as a list of space-delimited strings. - state: (optional) An opaque value used by the client to maintain state between the request and callback. |
$response |
\OAuth2\ResponseInterface | - Response object |
$is_authorized |
bool | - TRUE or FALSE depending on whether the user authorized the access. |
$user_id |
mixed | - Identifier of user who authorized the client |
See Also:
- http://tools.ietf.org/html/rfc6749#section-4 -
validateAuthorizeRequest
Pull the authorization request data out of the HTTP request.
public validateAuthorizeRequest(\OAuth2\RequestInterface $request, \OAuth2\ResponseInterface $response = null): bool
- The redirect_uri is OPTIONAL as per draft 20. But your implementation can enforce it by setting $config['enforce_redirect'] to true.
- The state is OPTIONAL but recommended to enforce CSRF. Draft 21 states, however, that CSRF protection is MANDATORY. You can enforce this by setting the $config['enforce_state'] to true.
The draft specifies that the parameters should be retrieved from GET, override the Response object to change this
Parameters:
Parameter | Type | Description |
---|---|---|
$request |
\OAuth2\RequestInterface | - Request object |
$response |
\OAuth2\ResponseInterface | - Response object |
Return Value:
The authorization parameters so the authorization server can prompt the user for approval if valid.
See Also:
- http://tools.ietf.org/html/rfc6749#section-4.1.1 - * http://tools.ietf.org/html/rfc6749#section-10.12 -
verifyResourceRequest
Verify the resource request
public verifyResourceRequest(\OAuth2\RequestInterface $request, \OAuth2\ResponseInterface $response = null, string $scope = null): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$request |
\OAuth2\RequestInterface | - Request object |
$response |
\OAuth2\ResponseInterface | - Response object |
$scope |
string | - Scope |
getAccessTokenData
Get access token data.
public getAccessTokenData(\OAuth2\RequestInterface $request, \OAuth2\ResponseInterface $response = null): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$request |
\OAuth2\RequestInterface | - Request object |
$response |
\OAuth2\ResponseInterface | - Response object |
addGrantType
public addGrantType(\OAuth2\GrantType\GrantTypeInterface $grantType, mixed $identifier = null): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$grantType |
\OAuth2\GrantType\GrantTypeInterface | |
$identifier |
mixed |
addStorage
Set a storage object for the server
Parameters:
Parameter | Type | Description |
---|---|---|
$storage |
object | - An object implementing one of the Storage interfaces |
$key |
mixed | - If null, the storage is set to the key of each storage interface it implements |
Throws:
See Also:
- \OAuth2\storageMap -
addResponseType
public addResponseType(\OAuth2\ResponseType\ResponseTypeInterface $responseType, mixed $key = null): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$responseType |
\OAuth2\ResponseType\ResponseTypeInterface | |
$key |
mixed |
Throws:
getScopeUtil
setScopeUtil
Parameters:
Parameter | Type | Description |
---|---|---|
$scopeUtil |
\OAuth2\ScopeInterface |
createDefaultAuthorizeController
Throws:
createDefaultTokenController
Throws:
createDefaultResourceController
Throws:
createDefaultUserInfoController
Throws:
getDefaultTokenType
getDefaultResponseTypes
Throws:
getDefaultGrantTypes
Throws:
getAccessTokenResponseType
getIdTokenResponseType
getIdTokenTokenResponseType
createDefaultJwtAccessTokenStorage
For Resource Controller
Throws:
createDefaultJwtAccessTokenResponseType
For Authorize and Token Controllers
Throws:
createDefaultAccessTokenResponseType
Throws:
createDefaultIdTokenResponseType
Throws:
createDefaultIdTokenTokenResponseType
validateOpenIdConnect
Throws:
normalizeResponseType
Parameters:
Parameter | Type | Description |
---|---|---|
$name |
string |
getResponse
getStorages
getStorage
Parameters:
Parameter | Type | Description |
---|---|---|
$name |
string |
getGrantTypes
getGrantType
Parameters:
Parameter | Type | Description |
---|---|---|
$name |
string |
getResponseTypes
getResponseType
Parameters:
Parameter | Type | Description |
---|---|---|
$name |
string |
getTokenType
getClientAssertionType
setConfig
Parameters:
Parameter | Type | Description |
---|---|---|
$name |
string | |
$value |
mixed |
getConfig
Parameters:
Parameter | Type | Description |
---|---|---|
$name |
string | |
$default |
mixed |
Automatically generated on 2025-03-18