예제 #1
0
// New creates a new request sourced from the client. If a signer is present on
// the client, requests will automatically be signed.
func (c *Client) New(context interface{}, verb, path string, body io.Reader) (*http.Request, error) {

	// Parse the base url passed in.
	uri, err := url.Parse(c.BaseURL)
	if err != nil {
		return nil, err
	}

	// Join the paths from the base url and the request path.
	uri.Path = stdpath.Join(uri.Path, path)

	req, err := http.NewRequest(verb, uri.String(), body)
	if err != nil {
		return nil, err
	}

	// If the authSigner is defined, it means that we can now sign the request
	// with the authentication token.
	if c.Signer != nil {

		// Sign the actual request without any extra claims added.
		if err := auth.SignRequest(context, c.Signer, nil, req); err != nil {
			return nil, err
		}
	}

	return req, nil
}
예제 #2
0
// SignServiceRequest signs a request with the claims necessary to authenticate
// with downstream services.
func SignServiceRequest(context interface{}, signer auth.Signer, r *http.Request) error {
	claims := map[string]interface{}{}

	return auth.SignRequest(context, signer, claims, r)
}