本文整理汇总了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);
}
}
示例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);
}
示例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;
}
示例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);
}
}
示例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);
}
示例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];
}
示例7: me
protected function me()
{
if ($token = JWTAuth::getToken()) {
return JWTAuth::parseToken()->toUser();
}
return false;
}
示例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]);
}
示例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'));
}
示例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.');
}
}
示例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)]);
}
示例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');
}
示例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']);
}
示例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'));
}
示例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'));
}