linkthrow/hmac-packet-auth

HMAC Http 数据包认证

v1.0.7 2016-12-02 14:20 UTC

This package is not auto-updated.

Last update: 2024-09-23 13:59:45 UTC


README

创建此包的主要动机是为了在基于 API 的通信中提供更多灵活性和安全性。我以前使用过 JWT,发现它非常容易被黑客攻击!

我遵循了 Twitter 提出的原则并实现了它们。

客户端

为了进行 API 请求,请使用以下插件 Angular

工作原理

客户端向 API 发送请求,并附带一系列头部信息。根据这些头部信息和请求数据生成 HMAC SHA512,从而消除了中间人攻击、重放攻击和注入攻击。

用户通过访问令牌(会过期)或 API 密钥进行识别。

头部信息包括

'key' or 'access-token'
'url'
'timestamp'
'client-nonce' (randomly generated string on the client side to prevent replay attacks as the nonce is stored against an api log on the database)
'hash' (generated with all the headers and request data as a json array)
'token' (not used to generate hash obviously)

快速开始

设置

运行 composer 命令

$ composer require linkthrow/hmac-packet-auth

在您的 config/app.php 中,将 'LinkThrow\HmacPacketAuth\Provider\HmacPacketAuthServiceProvider' 添加到 $providers 数组的末尾

'providers' => array(

    'Illuminate\Foundation\Providers\ArtisanServiceProvider',
    'Illuminate\Auth\AuthServiceProvider',
    ...
    'LinkThrow\HmacPacketAuth\Provider\HmacPacketAuthServiceProvider',

),

运行以下 artisan 命令以发布配置文件

$ php artisan vendor:publish

将以下属性添加到您的 .env 文件中

HMAC_AUTH_LOCAL=true
HMAC_AUTH_RATE_ON=true
HMAC_AUTH_RATE_TIME=60
HMAC_AUTH_RATE_LIMIT_NUMBER=60

运行以下 migrate 命令以添加所需的数据库表

$ php artisan migrate

将 'auth.hmac' 添加到您想要保护的任何路由中!!!

贡献

请阅读 CONTRIBUTING.md 以了解我们的行为准则以及向我们提交拉取请求的流程。

作者

  • Hussan Choudhry

还可以查看参与此项目的 贡献者列表

许可协议

此项目采用 MIT 许可协议 - 请参阅 LICENSE.md 文件以获取详细信息。