auth

package
v0.0.0-...-49d8a14 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2020 License: LGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

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 = iota
	AUTH_OAUTH2       = iota
	AUTH_COOKIE       = iota
	AUTH_INTERNAL     = iota
)
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)

Types

type AuthContext

type AuthContext struct {
	UserID           int
	Created          time.Time
	Updated          time.Time
	Username         string
	Email            string
	UserType         string
	URL              *string
	Location         *string
	Bio              *string
	SuspensionNotice *string
	AuthMethod       int

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

	// Only filled out if AuthMethod == AUTH_OAUTH2
	OAuth2Token *OAuth2Token
	Access      map[string]string
}

func ForContext

func ForContext(ctx context.Context) *AuthContext

type AuthCookie

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

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",omit-empty`
}

type OAuth2Token

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

func DecodeToken

func DecodeToken(token string) *OAuth2Token

func (*OAuth2Token) Encode

func (ot *OAuth2Token) Encode() string

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