本文整理汇总了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'));
}