This library piggy backs off of the Cloudflared CLI to allow you to perform authentication to Cloudflare Access applications using either user based auth or service token auth.
The library implements a http.RoundTripper
for authentication with a Cloudflare Access Application.
The examples below show an implementation for user and service auth that return a http.Client
for use by client wrappers.
An example of the user auth flow
appDomain := "https://<domain>/"
tr := http.DefaultTransport
transport, err := cf.NewAccessTokenClient(context, tr, appDomain)
if err != nil {
return err
}
client := &http.Client{Transport: transport}
An example of the service auth flow
tr := http.DefaultTransport
transport := cf.NewServiceTokenClient(tr, clientId, clientSecret)
client := &http.Client{Transport: transport}
The library is currently limited to only perform an initial token fetch at the creation of the RoundTripper
and as such is not designed to be used for long running operations.