/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if ($this->auth->check() && !\JWTAuth::getToken()) { return new RedirectResponse(url('/home')); } return $next($request); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { try { $payload = \JWTAuth::parseToken()->getPayload(); } catch (JWTException $e) { return $this->respond('tymon.jwt.invalid', 'token_invalid', $e->getStatusCode(), [$e]); } if ($payload['group'] != 'admin') { return $this->respond(404); } return $next($request); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { /* SOS: because sometimes missing HTTP_authorization header, because JWTAuth->request is DEFERRENT FROM $app['request'] JWTAuth::setRequest(Request::instance()); OR .htaaccess RewriteCond %{HTTP:Authorization} . RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] */ $app = app(); //language, currency, customer $language_id = $request->header('language-id'); $currency_id = $request->header('currency-id'); $customer_id = null; //customer $token = \JWTAuth::getToken(); //if (isset($token)) // $customer_id=\JWTAuth::GetUserFromToken($token); $app->context->init($language_id, $currency_id, $customer_id); /* $storeSettings=Session::get("settings", null); if (!isset($storeSettings)) { //load defaults $app->settings = new StoreSettings(); $app->settings->language = $app->languageService->getById(1); $app->settings->currency = $app->currencyService->getById(3); $app->settings->customer= null; $app->settings->save(); } else $app->settings=$storeSettings; $token = JWTAuth::getToken(); if (isset($token)) { $customer=JWTAuth::toUser($token); $app->settings->customer =$customer; } */ return $next($request); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed * @throws \App\Exceptions\InvalidCredentialsException * @throws \App\Exceptions\NoAuthenticationException */ public function handle($request, Closure $next) { if (empty($request->header('Authorization'))) { throw new \App\Exceptions\NoAuthenticationException(); } $header = $request->headers->get('Authorization'); if (starts_with(strtolower($header), 'bearer')) { //If token is passed (to refresh) /** @var User $user */ $user = \JWTAuth::setRequest($request)->parseToken()->authenticate(); \JWTAuth::invalidate(); //invalidate the old token $this->auth->setUser($user); } else { //if credentials are passed $credentials = ['email' => $request->getUser(), 'password' => $request->getPassword()]; $this->auth->once($credentials); } $isAuthenticated = $this->auth->check(); if (!$isAuthenticated) { throw new \App\Exceptions\InvalidCredentialsException(); } return $next($request); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed * @throws \App\Exceptions\InvalidCredentialsException * @throws \App\Exceptions\NoAuthenticationException */ public function handle($request, Closure $next) { $user = \JWTAuth::setRequest($request)->parseToken()->authenticate(); $this->auth->setUser($user); return $next($request); }