2017 © Pedro Peláez
 

library larsign

Laravel signature certification with web API server.

image

havenshen/larsign

Laravel signature certification with web API server.

  • Tuesday, December 5, 2017
  • by HavenShen
  • Repository
  • 1 Watchers
  • 6 Stars
  • 25 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 47 % Grown

The README.md

Api Authorized Signature Middleware for Laravel 5

Scrutinizer Code Quality Build Status Code Coverage Build Status Latest Stable Version Latest Unstable Version Latest Stable Version Total Downloads License, (*1)

About

The larsign package authorized signature server., (*2)

Features

  • Handles larsign requests

Installation

Laravel

Require the havenshen/larsign package in your composer.json and update your dependencies:, (*3)

$ composer require havenshen/larsign

Add the HavenShen\Larsign\LarsignServiceProvider to your config/app.php providers array:, (*4)

HavenShen\Larsign\LarsignServiceProvider::class,

Add the HavenShen\Larsign\LarsignFacade to your config/app.php aliases array:, (*5)

'Larsign' => HavenShen\Larsign\LarsignFacade::class,

Lumen

Require the havenshen/larsign package in your composer.json and update your dependencies:, (*6)

$ composer require havenshen/larsign

Register the package with lumen in bootstrap/app.php with the following:, (*7)

$app->register(HavenShen\Larsign\LarsignServiceProvider::class);

Global usage

To allow Larsign for all your routes, add the HandleLarsign middleware in the $middleware property of app/Http/Kernel.php class:, (*8)

protected $middleware = [
    // ...
    \HavenShen\Larsign\HandleLarsign::class,
];

Group middleware

If you want to allow Larsign on a specific middleware group or route, add the HandleLarsign middleware to your group:, (*9)

protected $middlewareGroups = [
    'web' => [
       // ...
    ],

    'api' => [
        // ...
        \HavenShen\Larsign\HandleLarsign::class,
    ],
];

Application route middleware

If you want to allow Larsign on a specific application middleware or route, add the HandleLarsign middleware to your application route:, (*10)

protected $routeMiddleware = [
    // ...
    'auth.larsign' => \HavenShen\Larsign\HandleLarsign::class,
];

Configuration

The defaults are set in config/larsign.php. Copy this file to your own config directory to modify the values. If you're using Laravel, you can publish the config using this command:, (*11)

$ php artisan vendor:publish --provider="HavenShen\Larsign\LarsignServiceProvider"

If you're using Lumen, Copy the configuration larsign.php from vendor/havenshen/larsign/config/larsign.php to your config/ directory, (*12)

return [
    /*
     |--------------------------------------------------------------------------
     | Larsign
     |--------------------------------------------------------------------------
     |
     */
    'headerName' => env('LARSIGN_HEADER_NAME', 'Larsign'),
    'accessKey' => env('LARSIGN_ACCESS_KEY', ''),
    'secretKey' => env('LARSIGN_SECRET_KEY', ''),
];

Add api route in routes/api.php Copy this., (*13)

Route::middleware(['auth.larsign'])->group(function () {
    Route::get('/larsign', function () {
    return [
        'message' => 'done.'
    ]);
});

or, (*14)

Route::get('/larsign', function () {
    return [
        'message' => 'done.'
    ];
})->middleware('auth.larsign');

Client

Generate Larsign signatures, (*15)

  1. Assume the following management credentials:
AccessKey = "test"
SecretKey = "123456"
  1. Call interface address:
url = "https://larsign.dev/api/v1/test?page=1"
  1. The original string to be signed: > note: the time-stamping followed by a newline [currenttime + voucher valid seconds]
signingStr = "/api/v1/test?page=1\n1510986405"
  1. Base64 url safe encode:
signingStrBase64UrlSafeEncode = "L2FwaS92MS90ZXN0P3BhZ2U9MQoxNTEwOTg2NDY1"
  1. hmac_sha1 carries SecretKey encryption then base64 url safe encode:
sign = "MLKnFIdI-0TOQ4mHn5TyCcmWACU="
  1. The final administrative credentials are: > note: stitching headerName Space AccessKey:sign:signingStrBase64UrlSafeEncode
larsignToken = "Larsign test:MLKnFIdI-0TOQ4mHn5TyCcmWACU=:L2FwaS92MS90ZXN0P3BhZ2U9MQoxNTEwOTg2NDY1"
  1. Add http header: > note: header key in config/larsign.php -> headerName
Larsign:Larsign test:MLKnFIdI-0TOQ4mHn5TyCcmWACU=:L2FwaS92MS90ZXN0P3BhZ2U9MQoxNTEwOTg2NDY1

Client signature authorization failed

Http Response: 403

Testing

$ phpunit

License

The MIT License (MIT). Please see License File for more information., (*16)

The Versions

05/12 2017

dev-master

9999999-dev

Laravel signature certification with web API server.

  Sources   Download

MIT

The Development Requires

by Avatar HavenShen

laravel api middleware authorization signature laravel-5-packages

05/12 2017

1.0.3

1.0.3.0

Laravel signature certification with web API server.

  Sources   Download

MIT

The Development Requires

by Avatar HavenShen

laravel api middleware authorization signature laravel-5-packages

05/12 2017

1.0.2

1.0.2.0

Laravel signature certification with web API server.

  Sources   Download

MIT

The Development Requires

by Avatar HavenShen

laravel api middleware authorization signature laravel-5-packages

05/12 2017

1.0.1

1.0.1.0

Laravel signature certification with web API.

  Sources   Download

MIT

The Development Requires

by Avatar HavenShen

05/12 2017

1.0.0

1.0.0.0

Laravel signature certification with web API.

  Sources   Download

MIT

The Development Requires

by Avatar HavenShen