oauth

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SessionAuthorizedToken is the key set in the gin context for the Token
	// of a User who has successfully passed Bearer token authorization.
	// The interface returned from grabbing this key should be parsed as oauth2.TokenInfo
	SessionAuthorizedToken = "authorized_token"
	// SessionAuthorizedUser is the key set in the gin context for the id of
	// a User who has successfully passed Bearer token authorization.
	// The interface returned from grabbing this key should be parsed as a *gtsmodel.User
	SessionAuthorizedUser = "authorized_user"
	// SessionAuthorizedAccount is the key set in the gin context for the Account
	// of a User who has successfully passed Bearer token authorization.
	// The interface returned from grabbing this key should be parsed as a *gtsmodel.Account
	SessionAuthorizedAccount = "authorized_account"
	// SessionAuthorizedApplication is the key set in the gin context for the Application
	// of a Client who has successfully passed Bearer token authorization.
	// The interface returned from grabbing this key should be parsed as a *gtsmodel.Application
	SessionAuthorizedApplication = "authorized_app"
	// OOBURI is the out-of-band oauth token uri
	OOBURI = "urn:ietf:wg:oauth:2.0:oob"
	// OOBTokenPath is the path to redirect out-of-band token requests to.
	OOBTokenPath = "/oauth/oob" // #nosec G101 else we get a hardcoded credentials warning
	// HelpfulAdvice is a handy hint to users;
	// particularly important during the login flow
	HelpfulAdvice      = "" /* 188-byte string literal not displayed */
	HelpfulAdviceGrant = "" /* 231-byte string literal not displayed */
)

Variables

This section is empty.

Functions

func DBTokenToToken

func DBTokenToToken(dbt *gtsmodel.Token) *models.Token

DBTokenToToken is a lil util function that takes a database token and gives back a gotosocial token

func InvalidRequest added in v0.3.5

func InvalidRequest() error

InvalidRequest returns an oauth spec compliant 'invalid_request' error.

func NewClientStore

func NewClientStore(db db.Basic) oauth2.ClientStore

NewClientStore returns an implementation of the oauth2 ClientStore interface, using the given db as a storage backend.

func TokenToDBToken

func TokenToDBToken(tkn *models.Token) *gtsmodel.Token

TokenToDBToken is a lil util function that takes a gotosocial token and gives back a token for inserting into a database.

Types

type Auth

type Auth struct {
	Token       oauth2.TokenInfo
	Application *gtsmodel.Application
	User        *gtsmodel.User
	Account     *gtsmodel.Account
}

Auth wraps an authorized token, application, user, and account. It is used in the functions GetAuthed and MustAuth. Because the user might *not* be authed, any of the fields in this struct might be nil, so make sure to check that when you're using this struct anywhere.

func Authed

func Authed(c *gin.Context, requireToken bool, requireApp bool, requireUser bool, requireAccount bool) (*Auth, error)

Authed is a convenience function for returning an Authed struct from a gin context. In essence, it tries to extract a token, application, user, and account from the context, and then sets them on a struct for convenience.

If any are not present in the context, they will be set to nil on the returned Authed struct.

If *ALL* are not present, then nil and an error will be returned.

If something goes wrong during parsing, then nil and an error will be returned (consider this not authed). Authed is like GetAuthed, but will fail if one of the requirements is not met.

type Server

type Server interface {
	HandleTokenRequest(r *http.Request) (map[string]interface{}, gtserror.WithCode)
	HandleAuthorizeRequest(w http.ResponseWriter, r *http.Request) gtserror.WithCode
	ValidationBearerToken(r *http.Request) (oauth2.TokenInfo, error)
	GenerateUserAccessToken(ctx context.Context, ti oauth2.TokenInfo, clientSecret string, userID string) (accessToken oauth2.TokenInfo, err error)
	LoadAccessToken(ctx context.Context, access string) (accessToken oauth2.TokenInfo, err error)
}

Server wraps some oauth2 server functions in an interface, exposing only what is needed

func New

func New(ctx context.Context, database db.Basic) Server

New returns a new oauth server that implements the Server interface

Jump to

Keyboard shortcuts

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