auth

package module
v0.0.0-...-44886cb Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: MIT Imports: 21 Imported by: 2

README

About GoActivityPub: Authorization

MIT Licensed Build Status Test Coverage Go Report Card

This project is part of the GoActivityPub library which helps with creating ActivityPub applications using the Go programming language.

It is a wrapper package around making compatible libraries as HTTP-Sig and OAuth2 interact with GoActiivtyPub.

It provides functions to append Authorization headers to requests made with the client module, and also middlewares for verifying incoming requests against remote actors.

You can find an expanded documentation about the whole library on SourceHut.

For discussions about the projects you can write to the discussions mailing list: ~mariusor/[email protected]

For patches and bug reports please use the dev mailing list: ~mariusor/[email protected]

Documentation

Index

Constants

ID is the type of authorization that IndieAuth is using

Variables

View Source
var (
	DefaultAuthorizeTypes = osin.AllowedAuthorizeType{osin.CODE, osin.TOKEN, ID}
	DefaultAccessTypes    = osin.AllowedAccessType{osin.AUTHORIZATION_CODE, osin.REFRESH_TOKEN, osin.PASSWORD, osin.CLIENT_CREDENTIALS}

	DefaultConfig = osin.ServerConfig{
		AuthorizationExpiration:   86400,
		AccessExpiration:          2678400,
		TokenType:                 "Bearer",
		AllowedAuthorizeTypes:     DefaultAuthorizeTypes,
		AllowedAccessTypes:        DefaultAccessTypes,
		ErrorStatusCode:           http.StatusForbidden,
		AllowClientSecretInParams: false,
		AllowGetAccessRequest:     false,
		RetainTokenAfterRefresh:   true,
		RedirectUriSeparator:      "\n",
	}
)
View Source
var AnonymousActor = vocab.Actor{
	ID:   vocab.PublicNS,
	Type: vocab.ActorType,
	Name: vocab.NaturalLanguageValues{
		vocab.NilLangRef: vocab.Content("Anonymous"),
	},
}
View Source
var DefaultKeyWaitLoadTime = 2 * time.Second
View Source
var EmptyLogFn = func(log.Ctx, string, ...interface{}) {}

Functions

func ErrFn

func ErrFn(logFn LoggerFn) optionFn

func LoadActorFromOAuthToken

func LoadActorFromOAuthToken(storage oauthStore, tok *oauth2.Token) (vocab.Actor, error)

func LoadRemoteKey

func LoadRemoteKey(ctx context.Context, c Client, iri vocab.IRI) (vocab.Actor, *vocab.PublicKey, error)

LoadRemoteKey fetches a remote Public Key and returns it's owner.

func LogFn

func LogFn(logFn LoggerFn) optionFn

func NewLogger

func NewLogger(opt ...optionFn) (*logger, error)

Types

type Account

type Account vocab.Actor

func (*Account) IsLogged

func (a *Account) IsLogged() bool

type ActorVerifier

type ActorVerifier interface {
	// Verify validates a request for the existence of an authorized ActivityPub [vocab.Actor] that has
	// operated it.
	Verify(*http.Request) (vocab.Actor, error)
}

ActorVerifier verifies if a http.Request contains information about an ActivityPub vocab.Actor that has operated it.

func HTTPSignatureResolver

func HTTPSignatureResolver(cl Client, initFns ...SolverInitFn) ActorVerifier

HTTPSignatureResolver returns a HTTP-Signature validator for loading f

func OAuth2Resolver

func OAuth2Resolver(cl Client, initFns ...SolverInitFn) ActorVerifier

OAuth2Resolver

func Resolver

func Resolver(cl Client, initFns ...SolverInitFn) ActorVerifier

type Client

type Client interface {
	CtxGet(context.Context, string) (*http.Response, error)
	CtxLoadIRI(context.Context, vocab.IRI) (vocab.Item, error)
}

type LoggerFn

type LoggerFn func(log.Ctx, string, ...interface{})

type Metadata

type Metadata struct {
	Pw         []byte `jsonld:"pw,omitempty"`
	PrivateKey []byte `jsonld:"key,omitempty"`
}

type OptionFn

type OptionFn func(s *Server) error

func WithClient

func WithClient(cl Client) OptionFn

func WithIRI

func WithIRI(i ...vocab.IRI) OptionFn

func WithLogger

func WithLogger(l log.Logger) OptionFn

func WithStorage

func WithStorage(st oauthStore) OptionFn

func WithURL

func WithURL(uu ...string) OptionFn

type Server

type Server struct {
	*osin.Server
	// contains filtered or unexported fields
}

func New

func New(optFns ...OptionFn) (*Server, error)

func (*Server) LoadActorFromRequest

func (s *Server) LoadActorFromRequest(r *http.Request, toIgnore ...vocab.IRI) (vocab.Actor, error)

LoadActorFromRequest reads the Authorization header of an HTTP request and tries to decode it either an OAuth2 or HTTP Signatures:

* For OAuth2 it tries to load the matching local actor and use it further in the processing logic. * For HTTP Signatures it tries to load the federated actor and use it further in the processing logic.

func (*Server) ValidateLoggedIn

func (s *Server) ValidateLoggedIn() func(next http.Handler) http.Handler

type SolverInitFn

type SolverInitFn = func(*config)

func SolverWithIgnoreList

func SolverWithIgnoreList(iris ...vocab.IRI) SolverInitFn

func SolverWithLocalIRIFn

func SolverWithLocalIRIFn(fn func(vocab.IRI) bool) SolverInitFn

func SolverWithLogger

func SolverWithLogger(l LoggerFn) SolverInitFn

func SolverWithStorage

func SolverWithStorage(s oauthStore) SolverInitFn

Jump to

Keyboard shortcuts

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