auth

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: MIT Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

View Source
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

func Apply(ctx context.Context, s *Spec, req *http.Request, body []byte, env *Env) error

Apply adds credentials to req according to a rendered spec. body is the request body as sent (needed for AWS payload hashing).

func CacheKey

func CacheKey(s *Spec) string

CacheKey identifies the token cache entry for a rendered oauth2 spec.

func DescribeCached

func DescribeCached(raw string, now time.Time) string

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

type AWSCredentials struct {
	AccessKeyID     string
	SecretAccessKey string
	SessionToken    string
}

AWSCredentials are static AWS credentials.

type Cache

type Cache interface {
	Get(key string) (string, bool)
	Set(key, value string) error
}

Cache stores tokens between invocations (backed by the apic session).

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

type Spec struct {
	Type    string
	Args    []string
	Options map[string]string
	Raw     string
}

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

func Parse(raw string) (*Spec, error)

Parse splits an auth spec such as `basic {{user}} {{password}}` or `aws service=execute-api region=eu-west-2`.

func (*Spec) Render

func (s *Spec) Render(fn func(string) (string, error)) (*Spec, error)

Render returns a copy of the spec with fn applied to every argument and option value (used to substitute {{placeholders}}).

func (*Spec) Texts

func (s *Spec) Texts() []string

Texts returns every string in the spec that may contain placeholders.

Jump to

Keyboard shortcuts

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