...
1## HMAC Go Examples
2
3This go module provides an interface for developers to authorize their HTTP
4requests with BSP HMAC Authentication.
5
6The interface [`HTTPSigner`](sign/signer.go) contains one method
7`Sign`, when invoked will use HMAC to sign the request and add it to the `Authorization` header of the request provided.
8
9### Getting Started
10
11There are two examples under the [examples](examples/) folder that demonstrate
12a HTTP `GET` and `POST` request. To run these examples follow the steps below:
13
141. Have a working Go environment. You can check whether go is installed on your
15 machine by running
16
17```bash
18$ go version
19go version go1.15.2 darwin/amd64
20```
21
222. Update the example with your organization, shared and secret keys
23
24```go
25req.Header.Add("Date", time.Now().UTC().Format(http.TimeFormat))
26req.Header.Add("nep-organization", "<your_organization>")
27req.Header.Add("Content-Type", "application/json")
28
29...
30
31// Replace the empty string with your shared key
32sharedKey := "<shared_key>"
33// Replace the empty string with your secret key
34secretKey := "<shared_key>"
35```
36
373. Run the go command to see the output
38
39```bash
40$ go run go/examples/get/main.go
41```
42
43or
44
45```bash
46$ go run go/examples/post/main.go
47```
48
49### Other Usages
50
511. You can copy the code in the [`access_key_signer.go`](sign/access_key_signer.go) and use it in your own project.
522. You can import this project as a Go module by adding the following import
53 statement in your code.
54
55```go
56import "github.com/NCR-Corporation/ncr-bsp-hmac/go/sign"
57```
58
59Subsequently, when you run `go build` or `go run`, the compiler should be able
60to automatically resolve the dependency and add it to your project.
View as plain text