3
* Spring Signage Ltd - http://www.springsignage.com
4
* Copyright (C) 2016 Spring Signage Ltd
12
use League\OAuth2\Server\Entity\AccessTokenEntity;
13
use League\OAuth2\Server\Entity\ClientEntity;
14
use League\OAuth2\Server\Entity\SessionEntity;
15
use League\OAuth2\Server\Exception\InvalidClientException;
16
use League\OAuth2\Server\Grant\AbstractGrant;
17
use League\OAuth2\Server\Util\SecureKey;
21
* @package Xibo\Helper
23
class McaasGrant extends AbstractGrant
30
protected $identifier = 'mcaas';
37
protected $responseType = null;
42
* @var \League\OAuth2\Server\AuthorizationServer
44
protected $server = null;
47
* Access token expires in override
51
protected $accessTokenTTL = null;
60
* @param string $clientId
61
* @param string $clientSecret
63
* @throws InvalidClientException
65
public function setClient($clientId, $clientSecret)
67
$this->client = $this->server->getClientStorage()->get(
71
$this->getIdentifier()
74
if (($this->client instanceof ClientEntity) === false) {
75
throw new InvalidClientException();
82
* Complete the client credentials grant
88
public function completeFlow()
90
// Validate any scopes that are in the request (should always return default)
91
$scopes = $this->validateScopes('', $this->client);
93
// Create a new session
94
$session = new SessionEntity($this->server);
95
$session->setOwner('client', $this->client->getId());
96
$session->associateClient($this->client);
98
// Generate an access token
99
$accessToken = new AccessTokenEntity($this->server);
100
$accessToken->setId(SecureKey::generate());
101
$accessToken->setExpireTime($this->getAccessTokenTTL() + time());
103
// Associate scopes with the session and access token
104
foreach ($scopes as $scope) {
105
$session->associateScope($scope);
108
foreach ($session->getScopes() as $scope) {
109
$accessToken->associateScope($scope);
114
$accessToken->setSession($session);
115
$accessToken->save();
117
return $accessToken->getId();
b'\\ No newline at end of file'