mirror of
https://github.com/elyby/oauth2-server.git
synced 2025-05-31 14:12:07 +05:30
61 lines
1.5 KiB
PHP
61 lines
1.5 KiB
PHP
<?php
|
|
/**
|
|
* @author Alex Bilbie <hello@alexbilbie.com>
|
|
* @copyright Copyright (c) Alex Bilbie
|
|
* @license http://mit-license.org/
|
|
*
|
|
* @link https://github.com/thephpleague/oauth2-server
|
|
*/
|
|
|
|
namespace OAuth2ServerExamples\Repositories;
|
|
|
|
use League\OAuth2\Server\Entities\ClientEntityInterface;
|
|
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
|
|
use OAuth2ServerExamples\Entities\ScopeEntity;
|
|
|
|
class ScopeRepository implements ScopeRepositoryInterface
|
|
{
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function getScopeEntityByIdentifier($scopeIdentifier)
|
|
{
|
|
$scopes = [
|
|
'basic' => [
|
|
'description' => 'Basic details about you',
|
|
],
|
|
'email' => [
|
|
'description' => 'Your email address',
|
|
],
|
|
];
|
|
|
|
if (array_key_exists($scopeIdentifier, $scopes) === false) {
|
|
return;
|
|
}
|
|
|
|
$scope = new ScopeEntity();
|
|
$scope->setIdentifier($scopeIdentifier);
|
|
|
|
return $scope;
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function finalizeScopes(
|
|
array $scopes,
|
|
$grantType,
|
|
ClientEntityInterface $clientEntity,
|
|
$userIdentifier = null
|
|
) {
|
|
// Example of programatically modifying the final scope of the access token
|
|
if ((int) $userIdentifier === 1) {
|
|
$scope = new ScopeEntity();
|
|
$scope->setIdentifier('email');
|
|
$scopes[] = $scope;
|
|
}
|
|
|
|
return $scopes;
|
|
}
|
|
}
|