Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4128197
AuthorizationCodeAuthorization.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
AuthorizationCodeAuthorization.php
View Options
<?php
namespace
MediaWiki\Extension\OAuth\AuthorizationProvider\Grant
;
use
DateInterval
;
use
Exception
;
use
League\OAuth2\Server\Exception\OAuthServerException
;
use
League\OAuth2\Server\Grant\AuthCodeGrant
;
use
League\OAuth2\Server\Grant\GrantTypeInterface
;
use
League\OAuth2\Server\RequestTypes\AuthorizationRequest
;
use
MediaWiki\Extension\OAuth\AuthorizationProvider\AuthorizationProvider
;
use
MediaWiki\Extension\OAuth\Entity\ClientEntity
;
use
MediaWiki\Extension\OAuth\Entity\UserEntity
;
use
Psr\Http\Message\ResponseInterface
;
use
Psr\Http\Message\ServerRequestInterface
;
class
AuthorizationCodeAuthorization
extends
AuthorizationProvider
{
/**
* @inheritDoc
*/
public
function
needsUserApproval
()
{
return
true
;
}
/**
* @return GrantTypeInterface
* @throws Exception
*/
protected
function
getGrant
():
GrantTypeInterface
{
$authCodeRepo
=
$this
->
getAuthCodeRepo
();
$refreshTokenRepo
=
$this
->
getRefreshTokenRepo
();
$grant
=
new
AuthCodeGrant
(
$authCodeRepo
,
$refreshTokenRepo
,
new
DateInterval
(
'PT10M'
)
);
if
(
!
$this
->
config
->
get
(
'OAuth2RequireCodeChallengeForPublicClients'
)
)
{
$grant
->
disableRequireCodeChallengeForPublicClients
();
}
return
$grant
;
}
/**
* @param ServerRequestInterface $request
* @return AuthorizationRequest
* @throws OAuthServerException
*/
public
function
init
(
ServerRequestInterface
$request
):
AuthorizationRequest
{
$authRequest
=
$this
->
server
->
validateAuthorizationRequest
(
$request
);
/** @var ClientEntity $client */
$client
=
$authRequest
->
getClient
();
'@phan-var ClientEntity $client'
;
if
(
!
$client
->
isUsableBy
(
$this
->
user
)
)
{
throw
OAuthServerException
::
accessDenied
(
'Client '
.
$client
->
getIdentifier
()
.
' is not usable by user with ID '
.
$this
->
user
->
getId
()
);
}
$userEntity
=
UserEntity
::
newFromMWUser
(
$this
->
user
);
$authRequest
->
setUser
(
$userEntity
);
$this
->
logAuthorizationRequest
(
__METHOD__
,
$authRequest
);
$this
->
logger
->
info
(
"OAuth2: Starting authorization request for client {client} and user (id) {user} "
,
[
'client'
=>
$authRequest
->
getClient
()->
getIdentifier
(),
'user'
=>
$authRequest
->
getUser
()->
getIdentifier
()
]
);
return
$authRequest
;
}
/**
* @param AuthorizationRequest $authRequest
* @param ResponseInterface $response
* @return ResponseInterface
*/
public
function
authorize
(
AuthorizationRequest
$authRequest
,
ResponseInterface
$response
):
ResponseInterface
{
$this
->
logAuthorizationRequest
(
__METHOD__
,
$authRequest
);
return
$this
->
server
->
completeAuthorizationRequest
(
$authRequest
,
$response
);
}
/**
* @param string $method
* @param AuthorizationRequest $authRequest
*/
protected
function
logAuthorizationRequest
(
$method
,
AuthorizationRequest
$authRequest
)
{
$this
->
logger
->
info
(
"OAuth2: Authorization request, func {func}, for client {client} "
.
"and user (id) {user} using grant
\"
{grant}
\"
"
,
[
'func'
=>
$method
,
'client'
=>
$authRequest
->
getClient
()->
getIdentifier
(),
'user'
=>
$authRequest
->
getUser
()->
getIdentifier
(),
'grant'
=>
$authRequest
->
getGrantTypeId
()
]
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Wed, Aug 19, 09:07 (2 w, 4 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
0b/7c/1b521486ac4ac1c2374a7db46214
Default Alt Text
AuthorizationCodeAuthorization.php (3 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment