oauth

package
v0.20.3 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2026 License: AGPL-3.0 Imports: 20 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

View Source
var ErrInvalidRequest = errors.New("invalid_request")

ErrInvalidRequest is an oauth spec compliant 'invalid_request' error.

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 NewClientStore

func NewClientStore(state *state.State) oauth2.ClientStore

NewClientStore returns a minimal implementation of oauth2.ClientStore interface, using state as storage.

Only GetByID is implemented, Set and Delete are stubs.

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 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)
	RevokeAccessToken(ctx context.Context, clientID string, clientSecret string, access string) gtserror.WithCode
}

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

func New

func New(
	ctx context.Context,
	state *state.State,
	validateURIHandler manage.ValidateURIHandler,
	clientScopeHandler server.ClientScopeHandler,
	authorizeScopeHandler server.AuthorizeScopeHandler,
	internalErrorHandler server.InternalErrorHandler,
	responseErrorHandler server.ResponseErrorHandler,
	userAuthorizationHandler server.UserAuthorizationHandler,
) Server

New returns a new oauth server that implements the Server interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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