Giter Site home page Giter Site logo

api-signature's Introduction

laravel api signature

Install

composer require hogus/api-signature

Publish Config

php artisan vendor:publish --provider=Hogus\\ApiSignature\\ApiSignatureServiceProvider

Env

#sign
API_SIGN_ENABLED=true
API_SIGN_SECRET=secret
#API_SIGN_KEY=sign
#API_SIGN_TIMESTAMP_KEY=timestamp
#API_SIGN_TIMEOUT=60

Http Middleware

Add the API signature middleware to the middleware aliases in your Kernel.php file:

protected $middlewareAliases = [
    //...,
    'sign' => \Hogus\ApiSignature\Middleware\ApiSignature::class,
]

Router

Apply the sign middleware to the desired routes or route groups:

Route::middleware('sign:api')->group(function () {
    // your routes
});

This ensures that the API signature will be verified for all requests to these routes.

Custom Exceptions (options)

If you want to handle API signature verification exceptions in a custom way, you can define a renderable closure in your app/Exceptions/Handler.php file. For example, to return a JSON response containing the error message:

use Hogus\ApiSignature\ApiSignatureException;
$this->renderable(function (ApiSignatureException $exception, $request) {
    return response()->json(['message' => $exception->getMessage()]);
});

Supports

  • MD5
  • Hash(sha256)

api-signature's People

Contributors

hogus2037 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.