basic

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package basic provides Basic credential authenticators.

Index

Examples

Constants

View Source
const MaxEntries = 256

MaxEntries bounds the work performed for one static Basic authentication.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Username  string
	Password  string
	Principal authentication.PrincipalSpec
}

Entry configures one accepted username and password pair.

type Static

type Static struct {
	// contains filtered or unexported fields
}

Static validates Basic credentials against a bounded immutable set. Only fixed-length keyed secret digests are retained and every entry is compared.

func NewStatic

func NewStatic(entries []Entry) (*Static, error)

NewStatic validates and copies entries.

Example
package main

import (
	"context"
	"fmt"

	authentication "github.com/faustbrian/go-authentication"
	"github.com/faustbrian/go-authentication/basic"
)

func main() {
	authenticator, _ := basic.NewStatic([]basic.Entry{{
		Username: "service", Password: "password",
		Principal: authentication.PrincipalSpec{Subject: "service-account"},
	}})
	result, err := authenticator.Authenticate(
		context.Background(),
		authentication.NewBasicCredential("service", "password"),
	)
	principal, authenticated := result.Principal()
	fmt.Println(err, authenticated, principal.Subject())
}
Output:
<nil> true service-account

func (*Static) Authenticate

func (s *Static) Authenticate(ctx context.Context, credential authentication.Credential) (authentication.Result, error)

Authenticate validates one Basic credential in constant work relative to the configured entry count.

Jump to

Keyboard shortcuts

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