Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrInvalidKeys is when certificates cannot be created for an http client. ErrInvalidKeys = fmt.Errorf("cdr : invalid mTLS cert/key combination") )
Functions ¶
func New ¶
New creates a new http client with certificates attached to it. Most of the funcitons in this cdr package require a *http.Client as an argument. This is the way to build that client.
Example ¶
package main import ( "github.com/fiskil/cdr" ) func main() { cert := []byte(`-----BEGIN CERTIFICATE----- MIIBhTCCASugAwIBAgIQIRi6zePL6mKjOipn+dNuaTAKBggqhkjOPQQDAjASMRAw DgYDVQQKEwdBY21lIENvMB4XDTE3MTAyMDE5NDMwNloXDTE4MTAyMDE5NDMwNlow EjEQMA4GA1UEChMHQWNtZSBDbzBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABD0d 7VNhbWvZLWPuj/RtHFjvtJBEwOkhbN/BnnE8rnZR8+sbwnc/KhCk3FhnpHZnQz7B 5aETbbIgmuvewdjvSBSjYzBhMA4GA1UdDwEB/wQEAwICpDATBgNVHSUEDDAKBggr BgEFBQcDATAPBgNVHRMBAf8EBTADAQH/MCkGA1UdEQQiMCCCDmxvY2FsaG9zdDo1 NDUzgg4xMjcuMC4wLjE6NTQ1MzAKBggqhkjOPQQDAgNIADBFAiEA2zpJEPQyz6/l Wf86aX6PepsntZv2GYlA5UpabfT2EZICICpJ5h/iI+i341gBmLiAFQOyTDT+/wQc 6MF9+Yw1Yy0t -----END CERTIFICATE-----`) privKey := []byte(`-----BEGIN EC PRIVATE KEY----- MHcCAQEEIIrYSSNQFaA2Hwf1duRSxKtLYX5CB04fSeQ6tF1aY/PuoAoGCCqGSM49 AwEHoUQDQgAEPR3tU2Fta9ktY+6P9G0cWO+0kETA6SFs38GecTyudlHz6xvCdz8q EKTcWGekdmdDPsHloRNtsiCa697B2O9IFA== -----END EC PRIVATE KEY-----`) client, _ := cdr.New(cert, privKey) _ = client }
Output:
func NewFromEnv ¶
NewFromEnv creates a new http client taking its certificates from environment variables. This ishelpful if the certificates are const. The environment variables are:
CDR_MTLS_CERTIFICATE CDR_MTLS_PRIVATE_KEY
Types ¶
type ErrNon2xxResponse ¶
type ErrNon2xxResponse struct { StatusCode int Response io.ReadCloser URL *url.URL }
ErrNon2xxResponse is returned when a non 2xx status code is received.
func (*ErrNon2xxResponse) Error ¶
func (e *ErrNon2xxResponse) Error() string
type RefreshTokenResponse ¶
type RefreshTokenResponse struct { AccessToken string `json:"access_token"` IDToken string `json:"id_token"` ExpiresIn int `json:"expires_in"` Scope string `json:"scope"` RefreshToken string `json:"refresh_token"` CDRArrangement string `json:"cdr_arrangement_id"` }
RefreshTokenResponse is a response you get from exchanging a refresh token.
func RefreshToken ¶
func RefreshToken(ctx context.Context, cli *http.Client, tokenEndpoint string, refreshToken string, clientID string, clientAssertion string) (RefreshTokenResponse, error)
RefreshToken gets a new access token from a refresh token.
Example ¶
package main import ( "context" "github.com/fiskil/cdr" "github.com/fiskil/cdr/assertions" ) func main() { ctx := context.Background() // Get a new http client with mTLS certs attached. cli, _ := cdr.NewFromEnv() // Get the token endpoint from the data holders well known config tokenEndpoint := "https://identity-mtls.cdr-api.bankaust.com.au/token" refreshToken := "my-refresh-token" clientID := "data-holders-client-id-for-me" signer, _ := assertions.NewSignerFromEnv() assertion, _ := signer.ClientAssertions(clientID, tokenEndpoint) tokenResponse, _ := cdr.RefreshToken(ctx, cli, tokenEndpoint, refreshToken, clientID, assertion) _ = tokenResponse }
Output:
Directories ¶
Path | Synopsis |
---|---|
Package assertions is used for signing assertions that are used when authenticating with a data holder.
|
Package assertions is used for signing assertions that are used when authenticating with a data holder. |
Package banking provides primitives to interact with the openapi HTTP API.
|
Package banking provides primitives to interact with the openapi HTTP API. |
Package common provides primitives to interact with the openapi HTTP API.
|
Package common provides primitives to interact with the openapi HTTP API. |
Package dcr provides primitives to interact with the openapi HTTP API.
|
Package dcr provides primitives to interact with the openapi HTTP API. |
Package energy provides primitives to interact with the openapi HTTP API.
|
Package energy provides primitives to interact with the openapi HTTP API. |
Package registry provides primitives to interact with the openapi HTTP API.
|
Package registry provides primitives to interact with the openapi HTTP API. |
Package storage provides encrypted data store on your local machine that can handle the process of getting refresh tokens for you.
|
Package storage provides encrypted data store on your local machine that can handle the process of getting refresh tokens for you. |
Click to show internal directories.
Click to hide internal directories.