本文整理汇总了PHP中Tymon\JWTAuth\Facades\JWTAuth::decode方法的典型用法代码示例。如果您正苦于以下问题:PHP JWTAuth::decode方法的具体用法?PHP JWTAuth::decode怎么用?PHP JWTAuth::decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tymon\JWTAuth\Facades\JWTAuth
的用法示例。
在下文中一共展示了JWTAuth::decode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUserFromCookie
public function getUserFromCookie($cookie)
{
$tokenObject = new Token($cookie);
// Get a payload info from the token
try {
$payload = JWTAuth::decode($tokenObject);
} catch (TokenExpiredException $e) {
$message = 'Token in cookie was expired';
throw new TokenInCookieExpiredException($message, null, $e);
}
// Get user by the payload info
try {
$user = $this->userUpdater->updateBaseInfo($payload);
} catch (RepositoryException $e) {
throw new AuthException($e->getMessage(), null, $e);
}
// Attempt to update his profile by API or just log the error
try {
$user = $this->userUpdater->updateAdditionalInfo($cookie, $user);
} catch (UpdatingFailureException $e) {
Log::warning('An additional user information was\'nt updated. ' . $e->getMessage());
}
// Login
Auth::login($user, true);
// Return an actual user model if login passes
if (Auth::check()) {
return $this->userRepository->findWithRelations(Auth::id(), ['localRole']);
} else {
throw new AuthException('Login error. User is not authorized.');
}
}
示例2: getUserByCookie
/**
* @param $cookie
*
* @return static
*/
public static function getUserByCookie($cookie)
{
$tokenObject = new Token($cookie);
$payload = JWTAuth::decode($tokenObject);
$userInfo = $payload->toArray();
// temp test user
$user = User::firstOrCreate(['email' => $userInfo['email']]);
$role = array_key_exists('role', $userInfo) ? $userInfo['role'] : "DEVELOPER";
$user->update(['bid' => $userInfo['id'], 'role' => $role, 'first_name' => $userInfo['email'], 'last_name' => '', 'phone' => '666-66-666', 'avatar' => 'http://www.gravatar.com/avatar/' . md5(strtolower(trim($userInfo['email']))) . '?d=retro', 'address' => 'iat: ' . $userInfo['iat'], 'job_id' => 1, 'department_id' => 1]);
return $user;
}
示例3: extractUserDataFromCookie
protected function extractUserDataFromCookie($cookie)
{
$tokenObject = new Token($cookie);
// Get a payload info from the token
try {
$payload = JWTAuth::decode($tokenObject);
} catch (TokenExpiredException $e) {
$message = 'Token in cookie was expired';
throw new TokenInCookieExpiredException($message, null, $e);
}
return $payload;
}
示例4: getUserFromCookie
public function getUserFromCookie($cookie)
{
$tokenObject = new Token($cookie);
try {
$payload = JWTAuth::decode($tokenObject);
} catch (TokenExpiredException $e) {
throw new TokenInCookieExpiredException('Token in cookie was expired', null, $e);
}
$userInfo = $payload->toArray();
$preparedUserInfo = $this->prepareUserData($userInfo);
$user = $this->userRepository->updateFirstOrCreate(['email' => $preparedUserInfo['email']], $preparedUserInfo);
$this->attachAdditionUserInfo($cookie, $user);
Auth::login($user, true);
if (Auth::check()) {
return $this->userRepository->findWithRelations(Auth::id(), ['role']);
} else {
throw new AuthException('Login error. User is not authorized.');
}
}