当前位置: 首页>>代码示例>>PHP>>正文


PHP Request::setUserResolver方法代码示例

本文整理汇总了PHP中Illuminate\Http\Request::setUserResolver方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::setUserResolver方法的具体用法?PHP Request::setUserResolver怎么用?PHP Request::setUserResolver使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Http\Request的用法示例。


在下文中一共展示了Request::setUserResolver方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: handle

 /**
  * Authenticate an incoming request.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Closure                 $next
  *
  * @return mixed
  */
 public function handle(Request $request, Closure $next)
 {
     $_token = $request->input('access-token');
     $_clientId = $request->input('client-id');
     //  Remove these arguments
     $request->offsetUnset('client-id');
     $request->offsetUnset('access-token');
     //  Just plain ol' bad...
     if (empty($_token) || empty($_clientId)) {
         $this->error('bad request: no token or client-id present');
         return ErrorPacket::create(Response::HTTP_BAD_REQUEST);
     }
     try {
         $_key = AppKey::byClientId($_clientId)->firstOrFail();
         $this->setSigningCredentials($_clientId, $_key->client_secret);
     } catch (\Exception $_ex) {
         $this->error('forbidden: invalid "client-id" [' . $_clientId . ']');
         return ErrorPacket::create(Response::HTTP_FORBIDDEN, 'Invalid "client-id"');
     }
     if (!$this->verifySignature($_token, $_clientId, $_key->client_secret)) {
         $this->error('bad request: signature verification fail');
         return ErrorPacket::create(Response::HTTP_BAD_REQUEST);
     }
     try {
         $_owner = $this->_locateOwner($_key->owner_id, $_key->owner_type_nbr);
     } catch (ModelNotFoundException $_ex) {
         $this->error('unauthorized: invalid "user" assigned to akt#' . $_key->id);
         return ErrorPacket::create(Response::HTTP_UNAUTHORIZED);
     }
     $request->setUserResolver(function () use($_owner) {
         return $_owner;
     });
     //$this->debug('token validated for client "' . $_clientId . '"');
     return parent::handle($request, $next);
 }
开发者ID:rajeshpillai,项目名称:dfe-console,代码行数:43,代码来源:AuthenticateOpsClient.php

示例2: setUser

 /**
  * Overrides the request's resolver for user()
  *
  * @param Illuminate\Http\Request $request
  */
 protected function setUser($request)
 {
     $userId = $this->server->getAccessToken()->getSession()->getOwnerId();
     $user = $this->user->findOrFail($userId);
     // Closure will encapsulate preceeding $user object for the
     // remainder of the request.
     $request->setUserResolver(function () use($user) {
         return $user;
     });
 }
开发者ID:jeffsrepoaccount,项目名称:resource-authorization,代码行数:15,代码来源:Middleware.php

示例3: authUser

 /**
  * auth user.
  *
  * @param Request                $request
  * @param ServerRequestInterface $serverRequest
  */
 protected function authUser(Request $request, ServerRequestInterface $serverRequest)
 {
     $userVerifier = app()->make(Oauth2Server::class)->getOptions()['user_verifier'];
     /** @var \RTLer\Oauth2\Authorize\UserVerifierInterface $userVerifierObj */
     $userVerifierObj = new $userVerifier();
     $user = $userVerifierObj->getUserByIdentifier($serverRequest->getAttribute('oauth_user_id'));
     Auth::setUser($user);
     $request->setUserResolver(function () use($user) {
         return $user;
     });
 }
开发者ID:rtler,项目名称:laravel-oauth2-server,代码行数:17,代码来源:ResourceServerMiddleware.php

示例4: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @param  string|null  $guard
  * @return mixed
  */
 public function handle($request, Closure $next, $guard = null)
 {
     $service = new Service();
     if ($service->authByToken($request->session()->get('token'))) {
         $request->setUserResolver(function () use($service) {
             return $service->getModel();
         });
         return $next($request);
     }
     if ($request->ajax()) {
         return response('Unauthorized.', 401);
     }
     return redirect(route('admin:login'));
 }
开发者ID:Golars,项目名称:Naissance_Laravel,代码行数:22,代码来源:AdminAuthenticate.php

示例5: bindContext

 /**
  * Bind the given security context to the Request and Container.
  *
  * @param string  $context
  * @param Request $request
  */
 public function bindContext($context, Request $request)
 {
     $security = $this->getSecurity($context);
     $this->container->instance(SecurityApi::class, $security);
     $this->container->bind(UrlGeneratorContract::class, function () use($security) {
         return $security->url();
     });
     $this->container->bind([UrlGenerator::class => 'url'], function (Container $container) use($security) {
         /** @var PermissionAwareUrlGeneratorExtension $url */
         $url = $container->make(PermissionAwareUrlGeneratorExtension::class);
         $url->setUrlGenerator($security->url());
         return $url;
     });
     $request->setUserResolver(function () use($security) {
         return $security->getUser();
     });
 }
开发者ID:digbang,项目名称:security,代码行数:23,代码来源:SecurityContext.php

示例6: setUserResolver

 /**
  * Set the user resolver callback.
  *
  * @param \Closure $callback
  * @return $this 
  * @static 
  */
 public static function setUserResolver($callback)
 {
     return \Illuminate\Http\Request::setUserResolver($callback);
 }
开发者ID:satriashp,项目名称:tour,代码行数:11,代码来源:_ide_helper.php

示例7: prepareRequest

 /**
  * Prepare the given request instance for use with the application.
  *
  * @param   \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Request
  */
 protected function prepareRequest(Request $request)
 {
     $request->setUserResolver(function () {
         return $this->make('auth')->user();
     })->setRouteResolver(function () {
         return $this->currentRoute;
     });
     return $request;
 }
开发者ID:laravel,项目名称:lumen-framework,代码行数:15,代码来源:Application.php


注:本文中的Illuminate\Http\Request::setUserResolver方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。