daps

package
v0.0.0-...-6254df8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 24, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildProviderHeader

func BuildProviderHeader(idTokenJSONTemplate string,
	idToken string) (string, error)

BuildProviderHeader assembles the response header value containing the connector's ID token we got from DAPS.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client to talk to a DAPS server. Never instantiate one directly, rather use NewClient.

func NewClient

func NewClient(host string, clientPvtKey string, clientCert string,
	serverCert string) (*Client, error)

NewClient builds an HTTP client to connect to the specified DAPS host using mTLS. host can be either a plain host name or a host name with a port number as in e.g. "whoopsie.dapsie.org:4433". clientCert and clientPvtKey are, respectively, the certificate and associated private key the client should use to authenticate with DAPS whereas serverCert is the DAPS server certificate the client should use to authenticate the server. All of them are supposed to be in PEM format.

func (*Client) PostForm

func (c *Client) PostForm(urlPath string, data url.Values,
	ensureResponseBody bool) (ResponseBody, error)

PostForm issues a POST to the specified URL path with data's keys and values URL-encoded as the request body.

If the server replies with a success code, the response body gets read entirely in memory and returned. The returned data buffer may be empty if the server returned no content. If you'd like to return an error in this case (e.g. you expect content), then set ensureResponseBody to true.

If the server replies with an error or a connection error occurs, you get back that error and a nil ResponseBody.

type IDRequest

type IDRequest struct {
	// identifies the connector within DAPS/IDS; usually a UUID.
	ConnectorID string
	// e.g. "https://consumerconnector.fiware.org"
	ConnectorAudience string
	// how many seconds from now before the JWT in the request expires.
	SecondsBeforeExpiry uint32
	// connector's own RSA private key in PEM format.
	PrivateKey string
	// connector's own certificate to authenticate with DAPS; paired to
	// the private key and in PEM format.
	ConnectorCertificate string
	// DAPS server certificate, in PEM format, the connector should use
	// to authenticate the server.
	ServerCertificate string
	// DAPS server host or host:port.
	ServerHost string
}

IDRequest holds the data needed to request an ID token from DAPS.

func (*IDRequest) IdentityToken

func (r *IDRequest) IdentityToken() (string, error)

IdentityToken requests an ID token for the connector from DAPS.

type ProviderHeader

type ProviderHeader struct {
	Type            string `json:"@type"`
	ID              string `json:"id"`
	Issued          string `json:"issued"`
	ModelVersion    string `json:"modelVersion"`
	IssuerConnector string `json:"issuerConnector"`
	SecurityToken   struct {
		Type        string `json:"@type"`
		TokenFormat string `json:"tokenFormat"`
		TokenValue  string `json:"tokenValue"`
	} `json:"securityToken"`
}

ProviderHeader holds the IDS server header we generate.

type ResponseBody

type ResponseBody []byte

ResponseBody holds any data returned in the HTTP response body.

func (ResponseBody) AsJSON

func (b ResponseBody) AsJSON(out interface{}) error

AsJSON converts ResponseBody to JSON using the provided data structure.

func (ResponseBody) AsJSONMap

func (b ResponseBody) AsJSONMap() (map[string]interface{}, error)

AsJSONMap converts ResponseBody to a generic JSON map.

func (ResponseBody) AsString

func (b ResponseBody) AsString() string

AsString converts ResponseBody to string.

func (ResponseBody) IsEmpty

func (b ResponseBody) IsEmpty() bool

IsEmpty tells if ResponseBody has any content.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL