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


PHP Facades\JWTAuth类代码示例

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


在下文中一共展示了JWTAuth类的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: 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

示例3: __construct

 public function __construct(User $user, Project $project, Invitation $invitation)
 {
     $this->loggedUser = JWTAuth::parseToken()->authenticate();
     $this->user = $user;
     $this->project = $project;
     $this->invitation = $invitation;
 }
开发者ID:rasparac,项目名称:diplomski,代码行数:7,代码来源:UsersController.php

示例4: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next, $aplicacion)
 {
     $metodo = $request->method();
     $user = JWTAuth::parseToken()->authenticate();
     switch ($metodo) {
         case 'GET':
             $tipo_permiso = 1;
             break;
         case 'POST':
             $tipo_permiso = 2;
             break;
         case 'PUT':
             $tipo_permiso = 2;
             break;
         case 'DELETE':
             $tipo_permiso = 2;
             break;
     }
     $privilegios = Privilegio::with('aplicacion')->where('user_id', $user->id)->where('aplicacion_id', $aplicacion);
     if ($tipo_permiso == 1) {
         $privilegios = $privilegios->where(function ($query) {
             $query->where('privilegios_tipo_id', 1)->orWhere('privilegios_tipo_id', 2);
         });
     } else {
         $privilegios = $privilegios->where('privilegios_tipo_id', $tipo_permiso);
     }
     $privilegios = $privilegios->first();
     if ($privilegios) {
         return $next($request);
     } else {
         return response('Unauthorized.', 401);
     }
 }
开发者ID:antoniopacheco,项目名称:CECINTRANET-API,代码行数:40,代码来源:PermisoAplicacion.php

示例5: postLogin

 /**
  * Handle a login request to the application.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function postLogin(Request $request)
 {
     $usernames = $this->loginUsername();
     if (!is_array($usernames)) {
         $usernames = [$usernames];
     }
     $usernamesR = [];
     foreach ($usernames as $username) {
         $usernamesR[$username] = 'required';
     }
     $this->validate($request, array_merge($usernamesR, ['password' => 'required']));
     // If the class is using the ThrottlesLogins trait, we can automatically throttle
     // the login attempts for this application. We'll key this by the username and
     // the IP address of the client making these requests into this application.
     $throttles = $this->isUsingThrottlesLoginsTrait();
     if ($throttles && $this->hasTooManyLoginAttempts($request)) {
         return $this->sendLockoutResponse($request);
     }
     $credentials = $this->getCredentials($request);
     if ($token = JWTAuth::attempt($credentials, $this->customClaims())) {
         return $this->handleUserWasAuthenticated($request, $throttles, $token);
     }
     // If the login attempt was unsuccessful we will increment the number of attempts
     // to login and redirect the user back to the login form. Of course, when this
     // user surpasses their maximum number of attempts they will get locked out.
     if ($throttles) {
         $this->incrementLoginAttempts($request);
     }
     return new JsonResponse([implode('.', $usernames) => [$this->getFailedLoginMessage()]], 422);
 }
开发者ID:thecsea,项目名称:jwt-auth,代码行数:36,代码来源:AuthenticatesUsers.php

示例6: refreshToken

 /**
  * Permintaan refresh token
  *
  * @param Request $request
  * @return array
  */
 public function refreshToken(Request $request)
 {
     $this->middleware('auth');
     $user = app('auth')->user();
     $newToken = JWTAuth::parseToken()->refresh();
     return ['status' => 'success', 'user' => $user, 'token' => $newToken];
 }
开发者ID:amteknologi,项目名称:e-commerce,代码行数:13,代码来源:LoginController.php

示例7: me

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

示例8: addPoint

 public function addPoint(Request $request)
 {
     $user = JWTAuth::parseToken()->authenticate();
     $user->points = $user->points + $request->input('amount');
     $user->save();
     return response()->json(['success' => true, 'message' => "Users points added", 'users' => $user]);
 }
开发者ID:jubaedprince,项目名称:nohunchAPI,代码行数:7,代码来源:UserController.php

示例9: register

 public function register(UserRequest $request)
 {
     $newUser = ['name' => $request->get('name'), 'email' => $request->get('email'), 'password' => bcrypt($request->get('password'))];
     $user = User::create($newUser);
     $token = JWTAuth::fromUser($user);
     return response()->json(compact('token'));
 }
开发者ID:everdaniel,项目名称:vue-starter-laravel-api,代码行数:7,代码来源:AuthController.php

示例10: 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

示例11: index

 public function index(FacebookAuthentication $request, FacebookGraphClient $client, FacebookUserResolver $resolver)
 {
     $data = $client->init($request->token)->getUser(['id', 'email', 'first_name', 'last_name']);
     $user = $resolver->findOrCreateUser($data);
     $customClaims = ['name' => $user->name, 'email' => $user->email, 'role' => $user->role, 'gravatar' => $user->gravatar];
     return api_response(200, ['token' => JWTAuth::fromUser($user, $customClaims)]);
 }
开发者ID:adiachenko,项目名称:catchy_api,代码行数:7,代码来源:FacebookController.php

示例12: auth

 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function auth(Request $request)
 {
     $customClaims = ['id' => '55dc13391846c68a1ad56daa', 'email' => 'admin@admin', 'role' => 'ADMIN', 'iat' => 1440615292];
     $payload = JWTFactory::make($customClaims);
     $data = JWTAuth::encode($payload);
     $redirectPath = $request->cookie('referer');
     return Redirect::to($redirectPath, 303)->withCookie('x-access-token', $data->get())->withCookie('serverUID', '55dc13391846c68a1ad56daa');
 }
开发者ID:a1ex7,项目名称:asciit,代码行数:13,代码来源:AuthController.php

示例13: auth

 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function auth(Request $request)
 {
     $userData = $this->currentUser->payloadInfo;
     $payload = JWTFactory::make($userData);
     $data = JWTAuth::encode($payload);
     $redirectPath = $request->cookie('referer');
     return Redirect::to($redirectPath, 303)->withCookie('x-access-token', $data->get())->withCookie('serverUID', $userData['id']);
 }
开发者ID:BinaryStudioAcademy,项目名称:reviewr,代码行数:13,代码来源:AuthController.php

示例14: signin

 public function signin()
 {
     $credentials = Input::only('email', 'password');
     if (!($token = JWTAuth::attempt($credentials))) {
         return Response::json(false, HttpResponse::HTTP_UNAUTHORIZED);
     }
     return Response::json(compact('token'));
 }
开发者ID:BaptisteDixneuf,项目名称:laravel-angularjs-jwt,代码行数:8,代码来源:UserController.php

示例15: postLogin

 public function postLogin(Request $request)
 {
     $credentials = $request->only('email', 'password');
     $token = JWTAuth::attempt($credentials);
     if (!$token) {
         return response()->json('Incorrect username or password combination.', Response::HTTP_UNAUTHORIZED);
     }
     return response()->json(compact('token'));
 }
开发者ID:fredlawl,项目名称:planebox-api,代码行数:9,代码来源:AuthController.php


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