apikey

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 9, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package apikey provides an authentication plugin that allows for authentication via apikeys.

Index

Constants

View Source
const (
	// PluginName is the name of this plugin.
	PluginName = "auth_apikey"

	// Constant nae used as the auth provider in API requests.
	ProviderName = "apikey"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APIOption

type APIOption func(*APIPlugin)

APIOptions allow configuration of the APIPlugin.

func WithKeyFunc

func WithKeyFunc(f KeyFunc) APIOption

WithKeyFunc sets the function used to fetch the owner of an API key.

func WithKeyPrefix

func WithKeyPrefix(prefix string) APIOption

WithKeyPrefix sets the prefix used to identify API keys.

type APIPlugin

type APIPlugin struct {
	PluginName string
	// contains filtered or unexported fields
}

APIPlugin is an authentication plugin that allows for api-key based authentication.

func Plugin

func Plugin(opts ...APIOption) *APIPlugin

Plugin for allowing requests to be authorized by an API key.

func (*APIPlugin) Deps

func (p *APIPlugin) Deps() []string

From prefab.DependentPlugin.

func (*APIPlugin) Init

func (p *APIPlugin) Init(ctx context.Context, r *prefab.Registry) error

From prefab.Plugin.

func (*APIPlugin) Name

func (p *APIPlugin) Name() string

From prefab.Plugin.

func (*APIPlugin) NewKey

func (p *APIPlugin) NewKey() string

NewKey can be used by an application to create a new key for storage.

type KeyFunc

type KeyFunc func(ctx context.Context, key string) (*KeyOwner, error)

KeyFunc is a function that returns the owner of an API key. Should be implemented by the application.

type KeyOwner

type KeyOwner struct {
	UserID        string
	Email         string
	EmailVerified bool
	Name          string
	KeyCreatedAt  time.Time
}

KeyOwner is used by the application to provide details about the owner of the API key.

Jump to

Keyboard shortcuts

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