承接 iget-master/token-auth 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

iget-master/token-auth

Composer 安装命令:

composer require iget-master/token-auth

包简介

A simple token based authentication guard for Laravel 5.2

README 文档

README

Using this guard, you can login your user like the default Laravel session guard, but the authorization will be persisted using a token passed through Authorization HTTP Header.

Installation

  1. Require iget-master/token-auth on composer
  2. Add the IgetMaster\TokenAuth\TokenAuthServiceProvider::class services provider on app.php configuration file.
  3. Change your guard driver to iget-token on auth.php

Usage

As on Laravel's default session guard, you must use Auth::attempt using the user credentials to try to login. If successful, you can use Auth::getToken() to get the 16 characters random Authorization Token.

On subsequent requests, the user should pass a Authorization http header with this token. If the token is valid, the user will be authenticated and you will be able to get current user using Auth::user().

If you are using the Laravel's default AuthController, you must update it, since you should send to the user the Authorization Token. Here is an example of AuthController@getLogin method:

/**
 * @param \Request $request
 * @return \Illuminate\Http\JsonResponse
 */
public function getLogin(Request $request)
{
	$success = false;

	if (Auth::attempt($request->only(['email', 'password']))) {
		$success = true;
		$token = Auth::getToken();
		$user_id = Auth::user()->id;
	}

	return response()->json(compact('success', 'token', 'user_id'));
}

Remember to include the Request class at top of your controller class:

use Illuminate\Http\Request;

You should change session.lifetime configuration to change the token's lifetime.

统计信息

  • 总下载量: 696
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 10
  • Watchers: 3
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2015-12-29

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固