access

package
v0.0.0-...-96e1417 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2019 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ServiceToken

type ServiceToken struct {
	// ID is the service token ID. This is used to identify the service which
	// is being authenticated.
	ID string

	// Secret is the Client-Secret value for the service token.
	Secret string
}

ServiceToken is a Cloudflare Access token used for services which need long-lived access.

func FindServiceToken

func FindServiceToken(directory, host string) (*ServiceToken, error)

FindServiceToken takes the given directory and path and attempts to load a service token for the given host.

func LoadServiceToken

func LoadServiceToken(filepath string) (*ServiceToken, error)

LoadServiceToken takes the given file path and parses a ServiceToken from the file contents.

If the file does not exist, then this function returns an error. See the ParseServiceToken() function for more details on how service tokens are parsed.

func ParseServiceToken

func ParseServiceToken(data string) (*ServiceToken, error)

ParseServiceToken converts a compound service token consisting of a Client-ID and a Client-Secret into a ServiceToken struct.

This function expects the client data to be stored on two lines as:

${CLIENT_ID}
${CLIENT_SECRET}

Whitespace in the Client-ID and Client-Secret will be stripped. The Client-ID must be in the form of:

${ID}.${HOST}

where ${HOST} is the hostname being connected to.

func (*ServiceToken) ModifyRequest

func (st *ServiceToken) ModifyRequest(req *http.Request)

ModifyRequest sets the request headers to the given token values.

type Token

type Token interface {
	ModifyRequest(r *http.Request)
}

Token is the interface to both types of token.

func GetToken

func GetToken(ctx context.Context, uri *url.URL, servicetokendir string,
	usecloudflared bool, w io.Writer) (Token, error)

GetToken attempts to get a token for the given uri.

This function first attempts to load a service token for the requested URI, then attempts to load a user JWT using cloudflared if no service token was found.

The writer argument is used to redirect os.Stderr from the subprocess (if one is spawned). If you want to silence the output from os.Stderr, use ioutil.Discard as the writer. If the writer is nil, it is implicitly converted to ioutil.Discard.

type Transport

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

Transport takes a Token and applies it to any requests sent using it.

func NewTransport

func NewTransport(token Token, rt http.RoundTripper) *Transport

NewTransport returns a new AccessRountTripper set to use the given token and parent round-tripper.

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip applies the token headers to the request and gets a response.

type UserToken

type UserToken struct {
	// JWT is the content of the user token.
	JWT string
}

UserToken represents a user token for the given service.

func FindUserToken

func FindUserToken(ctx context.Context, uri *url.URL, cloudflared bool, w io.Writer) (*UserToken, error)

FindUserToken attempts to fetch a user token for the given URI.

func (*UserToken) ModifyRequest

func (ut *UserToken) ModifyRequest(req *http.Request)

Jump to

Keyboard shortcuts

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