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


PHP JWTAuth::getToken方法代码示例

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


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

示例1: __construct

 public function __construct()
 {
     $this->app_list_limit = env('APP_LIST_LIMIT', 50);
     $token = JWTAuth::getToken();
     if (!empty($token)) {
         $user = JWTAuth::toUser($token);
         $this->logged_user = User::find($user->id);
     }
 }
开发者ID:Worklemon,项目名称:api,代码行数:9,代码来源:Request.php

示例2: postShow

 public function postShow()
 {
     if ($user = JWTAuth::toUser(JWTAuth::getToken())) {
         return response()->json(compact('user'));
     }
 }
开发者ID:developscript,项目名称:laravel-with-angular,代码行数:6,代码来源:ProfileController.php

示例3: inValidateToken

 public function inValidateToken()
 {
     $tempStorage = app('\\App\\Http\\Controllers\\TEMPStorage\\UserTempStorage');
     $tempStorage->forget('id_company');
     //set model login
     $user = JWTAuth::parseToken()->authenticate();
     $this->model->find($user->id)->update(['login' => 0]);
     JWTAuth::invalidate(JWTAuth::getToken());
     return API::response()->array(['message' => 'success'])->statusCode(200);
 }
开发者ID:masmike,项目名称:scafolding,代码行数:10,代码来源:AuthController.php

示例4: me

 protected function me()
 {
     if ($token = JWTAuth::getToken()) {
         return JWTAuth::parseToken()->toUser();
     }
     return false;
 }
开发者ID:zenoZz,项目名称:laravelapi,代码行数:7,代码来源:BaseController.php

示例5: refreshToken

 /**
  * Refresh Token
  * Invalidate the token, so user cannot use it anymore
  * and return a new token
  * 
  * @param Request $request
  */
 public function refreshToken()
 {
     try {
         if (!($token = JWTAuth::getToken())) {
             return response()->json(['error' => 'Token not provided'], 400);
         }
     } catch (Tymon\JWTAuth\Exceptions\TokenExpiredException $e) {
         return response()->json(['token_expired'], $e->getStatusCode());
     } catch (Tymon\JWTAuth\Exceptions\TokenInvalidException $e) {
         return response()->json(['token_invalid'], $e->getStatusCode());
     } catch (Tymon\JWTAuth\Exceptions\JWTException $e) {
         return response()->json(['token_absent'], $e->getStatusCode());
     }
     /*
     $token = JWTAuth::getToken();
     if(!$token){
     	//throw new BadRequestHtttpException('Token not provided');
                 return response()->json(['error' => 'Token not provided'], 400);			
     }
     */
     try {
         $token = JWTAuth::refresh($token);
     } catch (TokenInvalidException $e) {
         //throw new AccessDeniedHttpException('The token is invalid');
         return response()->json(['error' => 'The token is invalid'], 400);
     }
     return response()->json(compact('token'));
 }
开发者ID:Vladimir-Florian,项目名称:Pasu,代码行数:35,代码来源:UserController.php

示例6: getState

 public function getState()
 {
     $token = JWTAuth::getToken();
     $user = JWTAuth::toUser($token);
     $unlocked = $user->devices()->unlocked();
     $device_state = $unlocked->count() == 0 ? 1 : 0;
     $data = ['state' => $device_state, 'username' => $user->first_name];
     $this->putStats($user);
     return Response::json($data);
 }
开发者ID:JolitaGrazyte,项目名称:lockedornot,代码行数:10,代码来源:DeviceController.php

示例7: refreshToken

 /**
  * @return mixed
  */
 public function refreshToken()
 {
     $token = JWTAuth::getToken();
     if (!$token) {
         return $this->apiResponse(400, ['message' => TOKEN_NOT_PROVIDED]);
     }
     try {
         $token = JWTAuth::refresh($token);
     } catch (TokenInvalidException $e) {
         return $this->apiResponse(401, ['message' => TOKEN_INVALID]);
     }
     return $this->apiResponse(200, ['message' => TOKEN_REFRESHED, 'token' => $token]);
 }
开发者ID:Worklemon,项目名称:api,代码行数:16,代码来源:AuthController.php

示例8: refresh

 public function refresh()
 {
     $oldtoken = JWTAuth::getToken();
     try {
         // attempt to refresh token for the user
         if (!($token = JWTAuth::refresh($oldtoken))) {
             return $this->response->array(['error' => 'invalid_token'], 401);
         }
     } catch (JWTException $e) {
         return $this->response->array(['error' => 'could_not_refresh_token'], 500);
     }
     return $this->response->array(compact('token'));
 }
开发者ID:Bouhnosaure,项目名称:lia-api,代码行数:13,代码来源:JwtController.php

示例9: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, \Closure $next, $isRest = "Rest")
 {
     Log::debug("CheckJWT.handle.begin");
     $isAjax = $isRest == "Rest";
     Log::warning("Rest call:" . $isAjax);
     $jwt = DragoCookie::getCookie();
     $token = null;
     if ($jwt != null) {
         $token = JWTAuth::setToken($jwt);
     } else {
         $token = JWTAuth::getToken();
     }
     if ($token == null) {
         Log::warning("CheckJWT.handle.token invalid");
         if ($isAjax) {
             return response("token invalid", 401);
         } else {
             return redirect('login');
         }
     }
     try {
         $user = $token->authenticate();
         Log::debug("CheckJWT.handle.user:" . print_r($user, true));
     } catch (TokenExpiredException $e) {
         Log::warning("CheckJWT.handle.token expired");
         if ($isAjax) {
             return response("token expired", 401);
         } else {
             return redirect('login');
         }
     } catch (JWTException $e) {
         Log::warning("CheckJWT.handle.token invalid");
         if ($isAjax) {
             return response("token invalid", 401);
         } else {
             return redirect('login');
         }
     }
     if (!$user) {
         Log::warning("CheckJWT.handle.user not found");
         if ($isAjax) {
             return response("token invalid", 401);
         } else {
             return redirect('login');
         }
     }
     Log::debug("CheckJWT.handle.end");
     return $next($request);
 }
开发者ID:edragonetti,项目名称:empa-Assign,代码行数:56,代码来源:CheckJWT.php

示例10: handle

 /**
  * @param         $request
  * @param Closure $next
  * @param         $permission
  *
  * @return mixed
  */
 public function handle($request, Closure $next, $permission)
 {
     $token = JWTAuth::getToken();
     if (!$token) {
         return Response::apiResponse(['httpCode' => 400, 'message' => 'Token não encontrado ou inválido.']);
     }
     try {
         $user = $this->auth->authenticate($token);
     } catch (TokenExpiredException $e) {
         return Response::apiResponse(['httpCode' => 400, 'message' => 'O token de acesso expirou.']);
     } catch (JWTException $e) {
         return Response::apiResponse(['httpCode' => 400, 'message' => 'Token inválido.']);
     }
     if (!$user) {
         return Response::apiResponse(['httpCode' => 404, 'message' => 'Usuário não encontrado.']);
     }
     if (!$user->hasRole(explode('|', $permission))) {
         return Response::apiResponse(['httpCode' => 401, 'message' => 'Acesso não autorizado.']);
     }
     $this->events->fire('tymon.jwt.valid', $user);
     return $next($request);
 }
开发者ID:lfalmeida,项目名称:lbase,代码行数:29,代码来源:TokenEntrustPermission.php

示例11: getToken

 /**
  * Get the token.
  *
  * @return false|Token
  */
 public function getToken()
 {
     return JWTAuth::getToken();
 }
开发者ID:imjerrybao,项目名称:jwt-auth-guard,代码行数:9,代码来源:JwtAuthGuard.php

示例12: invalidateToken

 /**
  * to invalidate token
  * @return [type] [description]
  */
 protected function invalidateToken()
 {
     //logout if login withtout company
     $this->tempStorage->forget('id_company');
     \Tymon\JWTAuth\Facades\JWTAuth::invalidate(JWTAuth::getToken());
 }
开发者ID:masmike,项目名称:scafolding,代码行数:10,代码来源:BaseController.php

示例13: restricted

 public function restricted()
 {
     $token = JWTAuth::getToken();
     $user = JWTAuth::toUser($token);
     return Response::json(['data' => ['email' => $user->email, 'registered_at' => $user->created_at->toDateTimeString()]]);
 }
开发者ID:pavelmalai,项目名称:virtualcsgo,代码行数:6,代码来源:AuthCtrl.php

示例14: function

Route::get('/', function () {
    return view('spa');
});
/**
 * Registers a new user and returns a auth token
 */
Route::post('/signup', 'UserController@signup');
/**
 * Signs in a user using JWT
 */
Route::post('/signin', 'UserController@signin');
/**
 * Fetches a restricted resource from the same domain used for user authentication
 */
Route::get('/restricted', ['before' => 'jwt-auth', function () {
    $token = JWTAuth::getToken();
    $user = JWTAuth::toUser($token);
    return Response::json(['data' => ['email' => $user->email, 'registered_at' => $user->created_at->toDateTimeString(), 'role' => $user->role]]);
}]);
/**
 * Fetches a restricted resource from API subdomain using CORS
 */
Route::group(['domain' => '192.168.59.103', 'prefix' => 'api/v1', 'middleware' => 'jwt.auth'], function () {
    Route::get('/restricted', function () {
        try {
            JWTAuth::parseToken()->toUser();
        } catch (Exception $e) {
            return Response::json(['error' => $e->getMessage()], HttpResponse::HTTP_UNAUTHORIZED);
        }
        return ['data' => 'This has come from a dedicated API subdomain with restricted access.'];
    });
开发者ID:BaptisteDixneuf,项目名称:laravel-angularjs-jwt,代码行数:31,代码来源:routes.php

示例15: logout

 /**
  * Log out user. Blacklist the token.
  *
  * @return \Illuminate\Http\Response
  */
 public function logout()
 {
     JWTAuth::invalidate(JWTAuth::getToken());
     return 'Good';
 }
开发者ID:rossfinn1,项目名称:anvel-base-1,代码行数:10,代码来源:AuthController.php


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