Documentation
¶
Overview ¶
Package auth applies authentication to outgoing requests, driven by the `# @auth <type> [args]` directive or the `auth.default` setting in apic.yaml. Supported types: none, bearer, basic, aws, oauth2, exec.
Index ¶
- Variables
- func Apply(ctx context.Context, s *Spec, req *http.Request, body []byte, env *Env) error
- func CacheKey(s *Spec) string
- func DescribeCached(raw string, now time.Time) string
- func SignSigV4(req *http.Request, body []byte, creds AWSCredentials, service, region string, ...)
- type AWSCredentials
- type Cache
- type Env
- type Spec
Constants ¶
This section is empty.
Variables ¶
var Types = map[string]string{
"none": "send no credentials (overrides a project default)",
"bearer": "bearer <token>: Authorization: Bearer <token>",
"basic": "basic <user> <password>: HTTP basic auth",
"aws": "aws [service=execute-api] [region=..] [profile=..]: AWS Signature V4 using the SDK credential chain",
"oauth2": "oauth2 tokenUrl=.. clientId=.. [clientSecret=..] [grant=client_credentials|password|device_code] [scope=..] [username=..] [password=..] [audience=..] [deviceUrl=..] [clientAuth=body|basic]",
"exec": "exec <command> [args..] [header=Authorization] [prefix=Bearer] [ttl=10m]: use a command's stdout as the token (needs auth.allowExec in apic.yaml)",
}
Types lists the supported auth types with a one-line description.
Functions ¶
func Apply ¶
Apply adds credentials to req according to a rendered spec. body is the request body as sent (needed for AWS payload hashing).
func DescribeCached ¶
DescribeCached renders a cached token entry for `apic session`.
func SignSigV4 ¶
func SignSigV4(req *http.Request, body []byte, creds AWSCredentials, service, region string, at time.Time)
SignSigV4 signs req in place with AWS Signature Version 4 (header auth). body is the request body as sent. Behaviour matches the AWS SDK signer: the path is URI-encoded twice except for S3, query parameters are sorted, and Content-Length is signed when present.
Types ¶
type AWSCredentials ¶
AWSCredentials are static AWS credentials.
type Env ¶
type Env struct {
Cache Cache
Client *http.Client // used for token endpoints
AllowExec bool
Stderr io.Writer // device-code prompts
Now func() time.Time
}
Env is what Apply needs from the caller.
type Spec ¶
Spec is a parsed `# @auth` value. Args holds positional arguments and Options holds key=value arguments; both may still contain {{placeholders}} until the runner renders them.
func Parse ¶
Parse splits an auth spec such as `basic {{user}} {{password}}` or `aws service=execute-api region=eu-west-2`.