scopes() public method

Get the route scopes.
public scopes ( ) : array
return array
Example #1
0
 public function testControllerOptionsMergeAndOverrideRouteOptions()
 {
     $request = Request::create('foo', 'GET');
     $route = new Route($this->adapter, $this->container, $request, ['uri' => 'foo', 'methods' => ['GET', 'HEAD'], 'action' => ['scopes' => ['foo', 'bar'], 'providers' => ['foo'], 'limit' => 5, 'expires' => 10, 'throttle' => 'Foo', 'version' => ['v1'], 'conditionalRequest' => false, 'uses' => 'Dingo\\Api\\Tests\\Stubs\\RoutingControllerStub@index']]);
     $this->assertEquals(['foo', 'bar', 'baz', 'bing'], $route->scopes(), 'Route did not setup scopes correctly.');
     $this->assertEquals(['foo', 'red', 'black'], $route->getAuthProviders(), 'Route did not setup authentication providers correctly.');
     $this->assertEquals(10, $route->getRateLimit(), 'Route did not setup rate limit correctly.');
     $this->assertEquals(20, $route->getRateExpiration(), 'Route did not setup rate limit expiration correctly.');
     $this->assertTrue($route->hasThrottle(), 'Route did not setup throttle correctly.');
     $this->assertInstanceOf('Dingo\\Api\\Tests\\Stubs\\BasicThrottleStub', $route->getThrottle(), 'Route did not setup throttle correctly.');
 }
 /**
  * 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);
 }
Example #3
0
 /**
  * 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;
 }