项目作者: gin-contrib

项目描述 :
Signing HTTP Messages Middleware
高级语言: Go
项目地址: git://github.com/gin-contrib/httpsign.git
创建时间: 2018-10-31T03:08:42Z
项目社区:https://github.com/gin-contrib/httpsign

开源协议:MIT License

下载


httpsign

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

Signing HTTP Messages Middleware base on HTTP Signatures.

Example

  1. package main
  2. import (
  3. "github.com/gin-contrib/httpsign"
  4. "github.com/gin-contrib/httpsign/crypto"
  5. "github.com/gin-gonic/gin"
  6. )
  7. func main() {
  8. // Define algorithm
  9. hmacsha256 := &crypto.HmacSha256{}
  10. hmacsha512 := &crypto.HmacSha512{}
  11. // Init define secret params
  12. readKeyID := httpsign.KeyID("read")
  13. writeKeyID := httpsign.KeyID("write")
  14. secrets := httpsign.Secrets{
  15. readKeyID: &httpsign.Secret{
  16. Key: "HMACSHA256-SecretKey",
  17. Algorithm: hmacsha256, // You could using other algo with interface Crypto
  18. },
  19. writeKeyID: &httpsign.Secret{
  20. Key: "HMACSHA512-SecretKey",
  21. Algorithm: hmacsha512,
  22. },
  23. }
  24. // Init server
  25. r := gin.Default()
  26. //Create middleware with default rule. Could modify by parse Option func
  27. auth := httpsign.NewAuthenticator(secrets)
  28. r.Use(auth.Authenticated())
  29. r.GET("/a", a)
  30. r.POST("/b", b)
  31. r.POST("/c", c)
  32. r.Run(":8080")
  33. }