{"modulePath":"github.com/mutablelogic/go-server","version":"v1.4.15","isLatest":false,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package auth\n\n## Variables\n\n```go\nvar (\n\n\t// Root scope allows ANY operation\n\tScopeRoot = scopePrefix + \"root\"\n)\n```\n\n## Functions\n\n```go\nfunc New(c Config) (*auth, error)\n```\nCreate a new auth task from the configuration\n\n```go\nfunc TokenName(ctx context.Context) string\n```\nTokenName returns the token name from the context\n\n```go\nfunc TokenScope(ctx context.Context) []string\n```\nTokenScope returns the token scope from the context, or nil\n\n```go\nfunc WithToken(ctx context.Context, token Token) context.Context\n```\nWithToken returns a context with the given auth token\n\n```go\nfunc WithTokenName(ctx context.Context, token Token) context.Context\n```\nWithTokenName returns a context with the given auth token name\n\n```go\nfunc WithTokenScope(ctx context.Context, token Token) context.Context\n```\nWithTokenScope returns a context with the given auth token scope\n\n## Types\n\n```go\ntype Config struct {\n\tTokenJar   TokenJar `hcl:\"token_jar\" description:\"Persistent storage for tokens\"`\n\tTokenBytes int      `hcl:\"token_bytes\" description:\"Number of bytes in a token\"`\n\tBearer     bool     `hcl:\"bearer\" description:\"Use bearer token for authorization\"`\n}\n```\n\n```go\nfunc (Config) Description() string\n```\nDescription returns the description of the service\n\n```go\nfunc (Config) Name() string\n```\nName returns the name of the service\n\n```go\nfunc (c Config) New() (server.Task, error)\n```\nCreate a new task from the configuration\n\n```go\ntype Token struct {\n\tName   string    `json:\"name,omitempty\"`                            // Name of the token\n\tValue  string    `json:\"token,omitempty\"`                           // Token value\n\tExpire time.Time `json:\"expire_time,omitempty\"  writer:\",width:29\"` // Time of expiration for the token\n\tTime   time.Time `json:\"access_time,omitempty\" writer:\",width:29\"`  // Time of last access\n\tScope  []string  `json:\"scopes,omitempty\" writer:\",wrap\"`           // Authentication scopes\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewToken(name string, length int, duration time.Duration, scope ...string) Token\n```\nCreate a token of the specified number of bytes, with the specified duration and scope. If the duration is zero, the token will not expire.\n\n```go\nfunc (t Token) Equals(other Token) bool\n```\nCompares token name, value, expiry and scopes\n\n```go\nfunc (t Token) IsScope(scopes ...string) bool\n```\nReturn true if the token has the specified scope, and is valid\n\n```go\nfunc (t Token) IsValid() bool\n```\nReturn true if the token is valid (not expired)\n\n```go\nfunc (t Token) IsZero() bool\n```\nReturn true if the token is a zero token\n\n```go\nfunc (t Token) MarshalJSON() ([]byte, error)\n```\n\n```go\nfunc (t *Token) SetWrite()\n```\nFlag that the token is to be written to persistent storage and should not include the 'valid' field\n\n```go\nfunc (t Token) String() string\n```\n\n```go\ntype TokenCreate struct {\n\tName     string   `json:\"name,omitempty\"`     // Name of the token\n\tDuration duration `json:\"duration,omitempty\"` // Duration of the token, or zero for no expiration\n\tScope    []string `json:\"scopes,omitempty\"`   // Authentication scopes\n}\n```\n\n```go\nfunc NewCreateToken(name string, expires_in time.Duration, scope ...string) TokenCreate\n```\nCreate a new create token request\n\n```go\ntype TokenJar interface {\n\tserver.Task\n\n\t// Return all tokens\n\tTokens() []Token\n\n\t// Return a token from the jar by value, or an invalid token\n\t// if the token is not found. The method should update the access\n\t// time of the token.\n\tGetWithValue(string) Token\n\n\t// Return a token from the jar by name, or nil if the token\n\t// is not found. The method should not update the access time\n\t// of the token.\n\tGetWithName(string) Token\n\n\t// Put a token into the jar, assuming it does not yet exist.\n\tCreate(Token) error\n\n\t// Update an existing token in the jar, assuming it already exists.\n\tUpdate(Token) error\n\n\t// Remove a token from the jar, based on key.\n\tDelete(string) error\n}\n```\n\n","path":"github.com/mutablelogic/go-server/pkg/handler/auth","name":"auth","synopsis":"","isRedistributable":true}
