Documentation ¶
Index ¶
- func AuthKeyHeader(key *rsa.PublicKey) map[string][]string
- func Execute(httpClient HttpClient, request *http.Request, ...) (response *http.Response, err error)
- func JSONHeaders() map[string][]string
- func MergeHeaders(headers ...map[string][]string) map[string][]string
- type HttpClient
- type SignedRequest
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthKeyHeader ¶
AuthKeyHeader is a header prototype including an encoded RSA PublicKey
Example ¶
headers, err := json.Marshal(AuthKeyHeader(&privateKey.PublicKey)) if err != nil { fmt.Printf("error: %s", err.Error()) return } fmt.Println(string(headers))
Output: {"X-Yoti-Auth-Key":["MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCpTiICtL+ujx8D0FquVWIaXg+ajJadN5hsTlGUXymiFAunSZjLjTsoGfSPz8PJm6pG9ax1Qb+R5UsSgTRTcpZTps2RLRWr5oPfD66bz4l38QXPSvfg5o+5kNxyCb8QANitF7Ht/DcpsGpL7anruHg/RgCLCBFRaGAodfuJCCM9zwIDAQAB"]}
func Execute ¶
func Execute(httpClient HttpClient, request *http.Request, httpErrorMessages ...map[int]string) (response *http.Response, err error)
Execute makes a request to the specified endpoint, with an optional payload
func JSONHeaders ¶
JSONHeaders is a header prototype for JSON based requests
Example ¶
jsonHeaders, err := json.Marshal(JSONHeaders()) if err != nil { fmt.Printf("error: %s", err.Error()) return } fmt.Println(string(jsonHeaders))
Output: {"Accept":["application/json"],"Content-Type":["application/json"]}
func MergeHeaders ¶
MergeHeaders merges two or more header prototypes together from left to right
Example ¶
left := map[string][]string{"A": {"Value Of A"}} right := map[string][]string{"B": {"Value Of B"}} merged := MergeHeaders(left, right) fmt.Println(merged["A"]) fmt.Println(merged["B"])
Output: [Value Of A] [Value Of B]
Types ¶
type HttpClient ¶
HttpClient is a mockable HTTP Client Interface
type SignedRequest ¶
type SignedRequest struct { Key *rsa.PrivateKey HTTPMethod string BaseURL string Endpoint string Headers map[string][]string Params map[string]string Body []byte Error error }
SignedRequest is a builder for constructing a http.Request with Yoti signing
Example (GenerateDigest) ¶
msg := &SignedRequest{ HTTPMethod: http.MethodPost, Body: []byte("simple message body"), } fmt.Println(msg.generateDigest("endpoint"))
Output: POST&endpoint&c2ltcGxlIG1lc3NhZ2UgYm9keQ==
func (SignedRequest) Request ¶
func (msg SignedRequest) Request() (request *http.Request, err error)
Request builds a http.Request with signature headers
func (SignedRequest) WithPemFile ¶
func (msg SignedRequest) WithPemFile(in []byte) SignedRequest
WithPemFile loads the private key from a PEM file reader
Example ¶
msg := SignedRequest{}.WithPemFile([]byte(` -----BEGIN RSA PRIVATE KEY----- ` + exampleKey + ` -----END RSA PRIVATE KEY-----`)) fmt.Println(AuthKeyHeader(&msg.Key.PublicKey))
Output: map[X-Yoti-Auth-Key:[MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCpTiICtL+ujx8D0FquVWIaXg+ajJadN5hsTlGUXymiFAunSZjLjTsoGfSPz8PJm6pG9ax1Qb+R5UsSgTRTcpZTps2RLRWr5oPfD66bz4l38QXPSvfg5o+5kNxyCb8QANitF7Ht/DcpsGpL7anruHg/RgCLCBFRaGAodfuJCCM9zwIDAQAB]]
Click to show internal directories.
Click to hide internal directories.