承接 framgia/laravel-jwt 相关项目开发

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

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

framgia/laravel-jwt

Composer 安装命令:

composer require framgia/laravel-jwt

包简介

JSON Web Token (JWT) native guard for Laravel 5.2+

README 文档

README

Scrutinizer Code Quality Travis Build Status Packagist Version

This package provides a native Laravel driver for JWT Authentication.

Installation

To install this package you will need:

  • Laravel 5.2 +
  • PHP 5.5.9 + (Laravel dependency)

Install via composer - edit your composer.json to require the package.

"require": {
    "framgia/laravel-jwt": "0.1.*"
}

Then run composer update in your terminal to install it in.

OR

Run composer require framgia/laravel-jwt to automatically install latest version

After installation you need to add the service provider to your app.php config file.

'providers' => [
    // ...
    Framgia\Jwt\JwtServiceProvider::class,
    // ...
],

Configuration

Add the jwt driver configuration to your auth.php config file.

'guards' => [
    // ...
    'jwt' => [
        'driver' => 'jwt',
        'provider' => 'users', // May be replaced with preferred provider.
    ],
    // ...
],

laravel-jwt uses the application secret key for encrypting the tokens. You can use a separate key by defining the JWT_KEY environment variable in your server configuration or .env file.

In order to overwrite default settings publish the jwt.php config file to your project.

$ php artisan vendor:publish --provider="Framgia\Jwt\JwtServiceProvider"

Usage

To obtain the guard instance use the facade or service container.

Auth::guard('jwt');
app('auth')->guard('jwt');

The guard includes basic methods required by the Guard contract and following methods for authentication:

// Retrieve new authentication token by user credentials
$token = $guard->attempt($credentials);

// Blacklist current user token to discard authentication
$guard->logout();

In order to pass authentication, provide the returned token with Authorization header:

Authorization: Bearer TOKEN_HERE

By default token includes jit, sub and exp claims. If you need to provide custom claims, add ProvidesCredentials contract to your authenticatable instance.

// ...
use Framgia\Jwt\Contracts\ProvidesCredentials;
// ...

class User implements Authenticatable, ProvidesCredentials
{
    // ...

    /**
     * Get credentials for JWT.
     *
     * @return array
     */
    public function getCredentials()
    {
        return [
            'admin' => $this->isAdmin(),
            'role' => $this->role,
        ];
    }

    // ...
}

Contributing

Use the GitHub repository Issues to report bugs or Pull Requests to provide bug fixes and feature updates.

License

The MIT License (MIT)

Copyright (c) 2016 Framgia Vietnam Ltd.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

See Also

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 8
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-05-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固