Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
17 / 17 |
| AccessTokenEntity | |
100.00% |
1 / 1 |
|
100.00% |
5 / 5 |
9 | |
100.00% |
17 / 17 |
| getSession | |
100.00% |
1 / 1 |
2 | |
100.00% |
4 / 4 |
|||
| hasScope | |
100.00% |
1 / 1 |
2 | |
100.00% |
0 / 0 |
|||
| getScopes | |
100.00% |
1 / 1 |
2 | |
100.00% |
4 / 4 |
|||
| save | |
100.00% |
1 / 1 |
2 | |
100.00% |
7 / 7 |
|||
| expire | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
| <?php | |
| /** | |
| * OAuth 2.0 Access token entity | |
| * | |
| * @package league/oauth2-server | |
| * @author Alex Bilbie <hello@alexbilbie.com> | |
| * @copyright Copyright (c) Alex Bilbie | |
| * @license http://mit-license.org/ | |
| * @link https://github.com/thephpleague/oauth2-server | |
| */ | |
| namespace League\OAuth2\Server\Entity; | |
| /** | |
| * Access token entity class | |
| */ | |
| class AccessTokenEntity extends AbstractTokenEntity | |
| { | |
| /** | |
| * Get session | |
| * | |
| * @return \League\OAuth2\Server\Entity\SessionEntity | |
| */ | |
| public function getSession() | |
| { | |
| if ($this->session instanceof SessionEntity) { | |
| return $this->session; | |
| } | |
| $this->session = $this->server->getSessionStorage()->getByAccessToken($this); | |
| return $this->session; | |
| } | |
| /** | |
| * Check if access token has an associated scope | |
| * | |
| * @param string $scope Scope to check | |
| * | |
| * @return bool | |
| */ | |
| public function hasScope($scope) | |
| { | |
| if ($this->scopes === null) { | |
| $this->getScopes(); | |
| } | |
| return isset($this->scopes[$scope]); | |
| } | |
| /** | |
| * Return all scopes associated with the access token | |
| * | |
| * @return \League\OAuth2\Server\Entity\ScopeEntity[] | |
| */ | |
| public function getScopes() | |
| { | |
| if ($this->scopes === null) { | |
| $this->scopes = $this->formatScopes( | |
| $this->server->getAccessTokenStorage()->getScopes($this) | |
| ); | |
| } | |
| return $this->scopes; | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function save() | |
| { | |
| $this->server->getAccessTokenStorage()->create( | |
| $this->getId(), | |
| $this->getExpireTime(), | |
| $this->getSession()->getId() | |
| ); | |
| // Associate the scope with the token | |
| foreach ($this->getScopes() as $scope) { | |
| $this->server->getAccessTokenStorage()->associateScope($this, $scope); | |
| } | |
| return $this; | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function expire() | |
| { | |
| $this->server->getAccessTokenStorage()->delete($this); | |
| } | |
| } |