本文整理匯總了PHP中Tymon\JWTAuth\Facades\JWTAuth::refresh方法的典型用法代碼示例。如果您正苦於以下問題:PHP JWTAuth::refresh方法的具體用法?PHP JWTAuth::refresh怎麽用?PHP JWTAuth::refresh使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Tymon\JWTAuth\Facades\JWTAuth
的用法示例。
在下文中一共展示了JWTAuth::refresh方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: 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'));
}
示例2: 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]);
}
示例3: refresh
/**
* Refresh current expired token.
*
* @return string
*/
public function refresh()
{
$this->parseToken();
return JWTAuth::refresh();
}
示例4: 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'));
}