Example #1
0
 /**
  * Peform authentication before a request is executed.
  *
  * @param \Dingo\Api\Routing\Route $route
  * @param \Illuminate\Http\Request $request
  * @param dynamic                  $provider
  *
  * @return mixed
  */
 public function filter(Route $route, Request $request)
 {
     if ($this->routeNotProtected($route) || $this->userIsLogged()) {
         return;
     }
     $providers = array_merge(array_slice(func_get_args(), 2), $route->getAuthProviders());
     $this->auth->authenticate($providers);
 }
Example #2
0
 public function testProvidersAreFilteredWhenSpecificProviderIsRequested()
 {
     $this->router->setCurrentRoute($route = new Route(['GET'], 'foo', ['protected' => true]));
     $this->router->setCurrentRequest($request = Request::create('foo', 'GET'));
     $provider = Mockery::mock('Dingo\\Api\\Auth\\Provider');
     $provider->shouldReceive('authenticate')->once()->with($request, $route)->andReturn(true);
     $provider->shouldReceive('assert')->once()->andReturn('one');
     $auth = new Authenticator($this->router, $this->container, ['one' => $provider, 'two' => Mockery::mock('Dingo\\Api\\Auth\\Provider')]);
     $auth->authenticate(['one']);
     $this->assertEquals('one', $auth->getProviderUsed()->assert());
 }