auth

package module
v0.0.0-...-7ba95f8 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2025 License: MIT Imports: 22 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/go-activitypub-discuss@lists.sr.ht

For patches and bug reports please use the dev mailing list: ~mariusor/go-activitypub-dev@lists.sr.ht

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, osin.IMPLICIT}

	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.LangRefValue{
			Ref:   vocab.NilLangRef,
			Value: vocab.Content("Anonymous"),
		},
	},
}
View Source
var DefaultKeyWaitLoadTime = 2 * time.Second
View Source
var EmptyLogFn = func(log.Ctx, string, ...interface{}) {}

Functions

func ClientResolver

func ClientResolver(cl Client, initFns ...func(*actorResolver)) actorResolver

func ErrFn

func ErrFn(logFn LoggerFn) optionFn

func LoadActorFromOAuthToken

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

func LogFn

func LogFn(logFn LoggerFn) optionFn

func NewLogger

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

func NewServer

func NewServer(store osin.Storage, l log.Logger) (*osin.Server, error)

func SolverWithIgnoreList

func SolverWithIgnoreList(iris ...vocab.IRI) func(resolver *actorResolver)

func SolverWithLocalIRIFn

func SolverWithLocalIRIFn(fn func(vocab.IRI) bool) func(*actorResolver)

func SolverWithLogger

func SolverWithLogger(l LoggerFn) func(*actorResolver)

func SolverWithStorage

func SolverWithStorage(s oauthStore) func(*actorResolver)

Types

type Account

type Account vocab.Actor

func (*Account) IsLogged

func (a *Account) IsLogged() bool

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

Jump to

Keyboard shortcuts

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