auth

package
v0.0.0-...-bd40a71 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2024 License: BSD-3-Clause Imports: 24 Imported by: 56

Documentation

Index

Constants

View Source
const (
	RO = "RO"
	RW = "RW"
)
View Source
const (
	USER_UNCONFIRMED       = "unconfirmed"
	USER_ACTIVE_NON_PAYING = "active_non_paying"
	USER_ACTIVE_FREE       = "active_free"
	USER_ACTIVE_PAYING     = "active_paying"
	USER_ACTIVE_DELINQUENT = "active_delinquent"
	USER_ADMIN             = "admin"
	USER_UNKNOWN           = "unknown"
	USER_SUSPENDED         = "suspended"
)
View Source
const (
	AUTH_OAUTH_LEGACY  = "OAUTH_LEGACY"
	AUTH_OAUTH2        = "OAUTH2"
	AUTH_COOKIE        = "COOKIE"
	AUTH_INTERNAL      = "INTERNAL"
	AUTH_ANON_INTERNAL = "ANON_INTERNAL"
	AUTH_WEBHOOK       = "WEBHOOK"
)
View Source
const TokenVersion uint = 0

Variables

This section is empty.

Functions

func FetchMetaProfile

func FetchMetaProfile(ctx context.Context, username string, user *AuthContext) error

func LegacyOAuth

func LegacyOAuth(bearer string, hash [64]byte, w http.ResponseWriter,
	r *http.Request, next http.Handler)

TODO: Remove legacy OAuth support

func LookupTokenRevocation

func LookupTokenRevocation(ctx context.Context,
	username string, hash [64]byte, clientID string) (bool, error)

Returns true if this token or client ID has been revoked (and therefore should not be trusted)

func LookupUser

func LookupUser(ctx context.Context, username string, user *AuthContext) error

func Middleware

func Middleware(conf ini.File, apiconf string) func(http.Handler) http.Handler

func OAuth2

func OAuth2(token string, hash [64]byte, w http.ResponseWriter,
	r *http.Request, next http.Handler)

func RequireMiddleware

func RequireMiddleware(conf ini.File, apiconf string) func(http.Handler) http.Handler

func WebhookAuth

func WebhookAuth(ctx context.Context, auth *AuthContext,
	tokenHash [64]byte, rawGrants string, clientID *string,
	expires time.Time) (context.Context, error)

Returns an auth context configured for webhook delivery. This auth configuration is not possible during a normal GraphQL query, and is only used during webhook execution.

The "ctx" parameter should be a webhook context, and the "auth" parameter should be the authentication context from the request which caused the webhook to be fired.

Types

type AuthContext

type AuthContext struct {
	AuthMethod string
	IPAddress  string

	// Only filled out for non-anonymous authentication
	UserID           int
	Created          time.Time
	Updated          time.Time
	Username         string
	Email            string
	UserType         string
	URL              *string
	Location         *string
	Bio              *string
	SuspensionNotice *string

	// Only set for meta.sr.ht-api
	PGPKey *string

	// Only filled out if AuthMethod == AUTH_INTERNAL
	InternalAuth InternalAuth

	// Only filled out if AuthMethod == AUTH_OAUTH2 or AUTH_WEBHOOK
	BearerToken *BearerToken
	Grants      Grants
	TokenHash   [64]byte
}

func ForContext

func ForContext(ctx context.Context) *AuthContext

func (*AuthContext) Access

func (authctx *AuthContext) Access(scope, kind string) error

type AuthCookie

type AuthCookie struct {
	// The username of the authenticated user
	Name string `json:"name"`
}

type BearerToken

type BearerToken struct {
	Version  uint
	Expires  Timestamp
	Grants   string
	ClientID string
	Username string
}

func DecodeBearerToken

func DecodeBearerToken(token string) *BearerToken

func (*BearerToken) Encode

func (bt *BearerToken) Encode() string

type Grants

type Grants struct {
	ReadOnly bool
	// contains filtered or unexported fields
}

func DecodeGrants

func DecodeGrants(ctx context.Context, grants string) (Grants, error)

func (*Grants) Encode

func (g *Grants) Encode() string

func (*Grants) Has

func (g *Grants) Has(grant string, mode string) bool

type InternalAuth

type InternalAuth struct {
	// The username of the authenticated user
	Name string `json:"name"`

	// An arbitrary identifier for this internal user, e.g. "git.sr.ht"
	ClientID string `json:"client_id"`

	// An arbitrary identifier for this internal node, e.g. "us-east-3.git.sr.ht"
	NodeID string `json:"node_id"`

	// Only used by specific meta.sr.ht routes
	OAuthClientUUID string `json:"oauth_client_id,omitempty"`
}

type Timestamp

type Timestamp int64

func ToTimestamp

func ToTimestamp(t time.Time) Timestamp

func (Timestamp) Time

func (t Timestamp) Time() time.Time

Jump to

Keyboard shortcuts

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