Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

LeeEirc/httpsig

Open more actions menu
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

httpsig

httpsig is a go package with for HTTP Signature. It also implements extensions to the standard.

Usage

import "gopkg.in/twindagger/httpsig.v1"

Client

This example signs a request and includes the date, and (request-target) header components in the signature.

// set key as a string from file read, memory, etc.
req, _ := http.NewRequest("GET", "http://example.com/path/to/resource", nil)
signer, _ := httpsig.NewRequestSigner("my-key-id", key, "rsa-sha256")
err := signer.SignRequest(req, []string{"date", "(request-target)"}, jwt)

Server

This example verifies that a request contains a signature and returns a 401 Unauthorized response if a signature is not present or not verifiable.

func HandleReq(w http.ResponseWriter, r *http.Request) {
    parsed, err := ParseRequest(req)
    if err != nil {
        w.WriteHeader(http.StatusUnauthorized)
        return
    }
    publicKey := lookupPubKey(parsed.KeyId())
    verified, err := VerifySignature(parsed, publicKey)
    if err != nil || !verified {
        w.WriteHeader(http.StatusUnauthorized)
        return
    }
    w.WriteHeader(http.StatusOK)
    w.Write("Authoirzation Passed")
}

func main() {
    http.HandleFunc("/", HandleReq)
    http.ListenAndServe(":8080", nil)
}

Installation

go get gopkg.in/twindagger/httpsig.v1

License

MIT.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Go 93.0%
  • JavaScript 7.0%
Morty Proxy This is a proxified and sanitized view of the page, visit original site.