d-fal / httpsign

Signing HTTP Messages Middleware

Home Page:https://tools.ietf.org/html/draft-cavage-http-signatures-10

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

httpsign

Build Status codecov Go Report Card GoDoc Join the chat at https://gitter.im/gin-gonic/gin

Signing HTTP Messages Middleware base on HTTP Signatures.

Example

package main

import (
	"github.com/gin-contrib/httpsign"
	"github.com/gin-contrib/httpsign/crypto"
	"github.com/gin-gonic/gin"
)

func main() {
	// Define algorithm
	hmacsha256 := &crypto.HmacSha256{}
	hmacsha512 := &crypto.HmacSha512{}
	// Init define secret params
	readKeyID := httpsign.KeyID("read")
	writeKeyID := httpsign.KeyID("write")
	secrets := httpsign.Secrets{
		readKeyID: &httpsign.Secret{
			Key:       "HMACSHA256-SecretKey",
			Algorithm: hmacsha256, // You could using other algo with interface Crypto
		},
		writeKeyID: &httpsign.Secret{
			Key:       "HMACSHA512-SecretKey",
			Algorithm: hmacsha512,
		},
	}

	// Init server
	r := gin.Default()

	//Create middleware with default rule. Could modify by parse Option func
	auth := httpsign.NewAuthenticator(secrets)

	r.Use(auth.Authenticated())
	r.GET("/a", a)
	r.POST("/b", b)
	r.POST("/c", c)

	r.Run(":8080")
}

About

Signing HTTP Messages Middleware

https://tools.ietf.org/html/draft-cavage-http-signatures-10

License:MIT License


Languages

Language:Go 100.0%