本文整理匯總了PHP中League\OAuth2\Server\Entity\AccessTokenEntity::hasScope方法的典型用法代碼示例。如果您正苦於以下問題:PHP AccessTokenEntity::hasScope方法的具體用法?PHP AccessTokenEntity::hasScope怎麽用?PHP AccessTokenEntity::hasScope使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類League\OAuth2\Server\Entity\AccessTokenEntity
的用法示例。
在下文中一共展示了AccessTokenEntity::hasScope方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1:
function it_checks_if_multiple_valid_scopes_are_included_into_the_current_ones(ResourceServer $checker, AccessTokenEntity $accessTokenEntity)
{
$accessTokenEntity->hasScope('foo')->willReturn(true)->shouldBecalled();
$accessTokenEntity->hasScope('bar')->willReturn(true)->shouldBeCalled();
$checker->getAccessToken()->willReturn($accessTokenEntity)->shouldBeCalledTimes(2);
$this->hasScope(['foo', 'bar'])->shouldReturn(true);
}
示例2: validateRouteScopes
/**
* Validate a routes scopes.
*
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $token
* @param \Dingo\Api\Routing\Route $route
*
* @throws \League\OAuth2\Server\Exception\InvalidScopeException
*
* @return bool
*/
protected function validateRouteScopes(AccessTokenEntity $token, Route $route)
{
$scopes = $route->scopes();
if (empty($scopes)) {
return true;
}
foreach ($scopes as $scope) {
if ($token->hasScope($scope)) {
return true;
}
}
throw new InvalidScopeException($scope);
}
示例3: validateAllRouteScopes
/**
* Validate a route has all scopes.
*
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $token
* @param \Dingo\Api\Routing\Route $route
*
* @throws \League\OAuth2\Server\Exception\InvalidScopeException
*
* @return bool
*/
protected function validateAllRouteScopes(AccessTokenEntity $token, Route $route)
{
$scopes = $route->scopes();
foreach ($scopes as $scope) {
if (!$token->hasScope($scope)) {
throw new InvalidScopeException($scope);
}
}
return true;
}