Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gin-contrib/httpsign
Signing HTTP Messages Middleware
https://github.com/gin-contrib/httpsign
gin gin-gonic gin-middleware
Last synced: 1 day ago
JSON representation
Signing HTTP Messages Middleware
- Host: GitHub
- URL: https://github.com/gin-contrib/httpsign
- Owner: gin-contrib
- License: mit
- Created: 2018-10-31T03:08:42.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-12-29T00:36:02.000Z (25 days ago)
- Last Synced: 2025-01-14T03:08:10.036Z (8 days ago)
- Topics: gin, gin-gonic, gin-middleware
- Language: Go
- Homepage: https://tools.ietf.org/html/draft-cavage-http-signatures-10
- Size: 87.9 KB
- Stars: 65
- Watchers: 6
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# httpsign
[![Run Tests](https://github.com/gin-contrib/httpsign/actions/workflows/go.yml/badge.svg)](https://github.com/gin-contrib/httpsign/actions/workflows/go.yml)
[![codecov](https://codecov.io/gh/gin-contrib/httpsign/branch/master/graph/badge.svg)](https://codecov.io/gh/gin-contrib/httpsign)
[![Go Report Card](https://goreportcard.com/badge/github.com/gin-contrib/httpsign)](https://goreportcard.com/report/github.com/gin-contrib/httpsign)
[![GoDoc](https://godoc.org/github.com/gin-contrib/httpsign?status.svg)](https://godoc.org/github.com/gin-contrib/httpsign)
[![Join the chat at https://gitter.im/gin-gonic/gin](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/gin-gonic/gin)Signing HTTP Messages Middleware base on [HTTP Signatures](https://tools.ietf.org/html/draft-cavage-http-signatures).
## Example
``` go
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")
}
```