A Go module to generate authentication details to communicate with Modo servers
Credentials that are created and shared by Modo. These will be different for each environment (int
, prod
, local
etc...).
APIIdentifier
- API key from ModoAPISecret
- API secret from Modo
These values will be used when intantiating the library.
# in the root of the project
go get github.com/modopayments-ux/modo2auth-go
Note: This package assumes your project to be a go module. If it is not, you may get an error looking for a main()
function definition.
Here's an example using ...
to make requests. You can use your preferred method or library.
package main
import (
"fmt" // for example
"io/ioutil" // for example
"net/http"
// 1. IMPORT
"github.com/modopayments-ux/modo2auth-go"
)
func main() {
// 2. INSTANTIATE - get these from MODO
modo := modo2auth.Config{
APIIdentifier: "...",
APISecret: "...",
}
// 3. SIGN & SEND REQUEST
apiHOST := "http://localhost:82"
apiURI := "/v2/vault/public_key"
req, _ := http.NewRequest("GET", apiHOST+apiURI, nil)
signedReq, _ := modo.Sign(req)
resp, _ := http.DefaultClient.Do(signedReq)
readBody, _ := ioutil.ReadAll(resp.Body)
fmt.Println("Response body is", string(readBody))
}
package main
import (
"fmt" // for example
"io/ioutil" // for example
"net/http"
// 1. IMPORT
"github.com/modopayments-ux/modo2auth-go"
)
func main() {
// 2. INSTANTIATE - get these from MODO
modo := modo2auth.Config{
APIIdentifier: "...",
APISecret: "...",
}
// 3. SIGN & SEND REQUEST
apiHOST := "http://localhost:82"
apiURI := "/v2/reports"
// format body data
data := map[string]string{
"start_date": "2020-05-01T00:00:00Z",
"end_date": "2020-05-26T00:00:00Z",
}
jsonData, _ := json.Marshal(data)
body := bytes.NewBuffer(jsonData)
// request
req, _ := http.NewRequest("POST", apiHOST+apiURI, body)
signedReq, _ := modo.Sign(req)
resp, _ := http.DefaultClient.Do(signedReq)
// response
respBody, _ := ioutil.ReadAll(resp.Body)
fmt.Println("Response body is", string(respBody))
}
Returns a Modo2Api Config struct.
APIIdentifier
(string) - API key from ModoAPISecret
(string) - API secret from ModoDebug
(bool) - Enables static values for testing
Returns an *http.Request
with a Modo2Auth token added as an Authorization header.
http.Request
(object) - HTTP request being made
Returns a Modo2Auth token (string) to be added to an HTTP request as an Authorization header ({Authorization: value}
).
apiURI
([]byte
) - Api Uri intending to call to (ex:"/v2/vault/public_key"
)body
([]byte
) - Body of the request- should be stringified JSON
- for
GET
requests, leave asnil
modo
(modo2auth.ID
) - Credentials for requests
Prerequisite: go
installed globally
- Install ...
- ...
- Unit test -
...
- Fork this repo via Github
- Create your feature branch (
git checkout -b feature/my-new-feature
) - Ensure unit tests are passing (
go test
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin feature/my-new-feature
) - Create new Pull Request via Github
Prequisite: Need to have go
installed on your system. At the root of this directory, do the following:
- Tag with new version
git tag v1.1.0
(According to Semantec Versioning guidelines) - Push tags
git push --tags
- ...