Skip to content

hmac is a Go module that offers services for HTTP HMAC authentication.

License

Notifications You must be signed in to change notification settings

pascalallen/hmac

Repository files navigation

hmac

Go Reference GitHub go.mod Go version Go Report Card GitHub Workflow Status (with branch) GitHub GitHub code size in bytes

hmac is a Go module that offers services for HTTP HMAC authentication.

Installation

Use the Go CLI tool go to install hmac.

go get github.com/pascalallen/hmac

Usage

...

import "github.com/pascalallen/hmac"

...

publicKey := hmac.GenerateSecureRandom(16)
privateKey := hmac.GenerateSecureRandom(16)
var timeTolerance int64 = 300

request, _ := http.NewRequest(
    http.MethodPost,
    "http://localhost:8080?abc=xyz",
    bytes.NewReader([]byte(`{"foo": "bar"}`)),
)

// create request service and sign request
requestService, _ := hmac.NewRequestService(publicKey, privateKey)
signedRequest := requestService.SignRequest(request)

// create authenticator and validate signed request
authenticator, _ := hmac.NewAuthenticator(publicKey, privateKey, timeTolerance)
isValid := authenticator.Validate(*signedRequest)

...

Testing

Run tests and create coverage profile:

go test -covermode=count -coverprofile=coverage.out

View test coverage profile:

go tool cover -html=coverage.out

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

About

hmac is a Go module that offers services for HTTP HMAC authentication.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages