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


PHP JWTAuth::decode方法代码示例

本文整理汇总了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.');
     }
 }
开发者ID:B1naryStudio,项目名称:asciit,代码行数:31,代码来源:AuthService.php

示例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;
 }
开发者ID:BinaryStudioAcademy,项目名称:reviewr,代码行数:16,代码来源:UserRepository.php

示例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;
 }
开发者ID:BinaryStudioAcademy,项目名称:reviewr,代码行数:12,代码来源:AuthService.php

示例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.');
     }
 }
开发者ID:a1ex7,项目名称:asciit,代码行数:19,代码来源:AuthService.php


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