承接 mxl/laravel-api-key 相关项目开发

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

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

mxl/laravel-api-key

Composer 安装命令:

composer require mxl/laravel-api-key

包简介

API key authorization for Laravel with replay attack prevention

README 文档

README

Current version Monthly Downloads Total Downloads Build Status

API Key Authorization for Laravel with replay attack prevention

Installation

$ composer require mxl/laravel-api-key

How it works?

Both sides (i.e. client and server) have a secret key. Client calculates a token - hash value for concatenated secret key and current timestamp. The Token and the timestamp are sent with request to server as separate HTTP headers. Server recalculates hash value and validates the token by comparing it with this value and by checking that received timestamp belongs to current time ± window interval.

Configuration

Package uses default configuration from vendor/laravel-api-key/config/apiKey.php:

<?php

return [
    'secret' => env('API_KEY_SECRET'),
    'hash' => env('API_KEY_HASH', 'md5'),
    'timestampHeader' => env('API_KEY_TIMESTAMP_HEADER', 'X-Timestamp'),
    'tokenHeader' => env('API_KEY_TOKEN_HEADER', 'X-Authorization'),
    'window' => env('API_KEY_WINDOW', 30),
];

To change it set environment variables mentioned in this configuration or copy it to your project with:

$ php artisan vendor:publish --provider="MichaelLedin\LaravelApiKey\ApiKeyServiceProvider" --tag=config

and modify config/apiKey.php file.

Notice! If you use php artisan config:cache or php artisan optimize command then you have to publish configuration as described above otherwise env() function will return null for all environment variables. Read more.

The configuration has following parameters:

  • secret - secret key that is known by client and server;
  • hash - an algorithm used to create hash value from secret key and timestamp; for a list of supported algorithms check an output of hash_algos function;
  • timestampHeader - HTTP header used to pass a timestamp;
  • tokenHeader - HTTP header used to pass a token;
  • window - window interval, in seconds;

Usage

Assign the middleware to routes using middleware class name:

use \MichaelLedin\LaravelApiKey\AuthorizeApiKey;

Route::get('admin/profile', function () {
    //
})->middleware(AuthorizeApiKey::class);

or an alias:

Route::get('admin/profile', function () {
    //
})->middleware('apiKey');

Maintainers

Other useful Laravel packages from the author

License

See the LICENSE file for details.

统计信息

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

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-04-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固