oauth

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContextKeyUserID   = "oauth_user_id"
	ContextKeyClientID = "oauth_client_id"
	ContextKeyScope    = "oauth_scope"
)

Variables

This section is empty.

Functions

func GenerateClientID

func GenerateClientID() (string, error)

func GenerateCodeChallenge

func GenerateCodeChallenge(codeVerifier string) string

func GetOAuthClientID

func GetOAuthClientID(c echo.Context) string

func GetOAuthScope

func GetOAuthScope(c echo.Context) string

func GetOAuthUserID

func GetOAuthUserID(c echo.Context) model_db.BinaryUUID

func GetUserIDFromSession

func GetUserIDFromSession(sess *sessions.Session) (string, bool)

func HasScope

func HasScope(c echo.Context, requiredScope string) bool

func ValidatePKCE

func ValidatePKCE(codeVerifier, codeChallenge, method string) bool

Types

type BunClientStore

type BunClientStore struct {
	// contains filtered or unexported fields
}

func NewBunClientStore

func NewBunClientStore(db *bun.DB) *BunClientStore

func (*BunClientStore) Create

func (s *BunClientStore) Create(ctx context.Context, client *OAuthClient) error

func (*BunClientStore) GetByID

func (s *BunClientStore) GetByID(ctx context.Context, id string) (oauth2.ClientInfo, error)

func (*BunClientStore) GetClientName

func (s *BunClientStore) GetClientName(ctx context.Context, clientID string) (string, error)

func (*BunClientStore) GetRedirectURIs

func (s *BunClientStore) GetRedirectURIs(ctx context.Context, clientID string) ([]string, error)

func (*BunClientStore) ValidateRedirectURI

func (s *BunClientStore) ValidateRedirectURI(ctx context.Context, clientID, redirectURI string) error

type BunTokenStore

type BunTokenStore struct {
	// contains filtered or unexported fields
}

func NewBunTokenStore

func NewBunTokenStore(db *bun.DB) *BunTokenStore

func (*BunTokenStore) Create

func (s *BunTokenStore) Create(ctx context.Context, info oauth2.TokenInfo) error

func (*BunTokenStore) CreateWithPKCE

func (s *BunTokenStore) CreateWithPKCE(ctx context.Context, info oauth2.TokenInfo, codeChallenge, codeChallengeMethod string) error

func (*BunTokenStore) GetByAccess

func (s *BunTokenStore) GetByAccess(ctx context.Context, access string) (oauth2.TokenInfo, error)

func (*BunTokenStore) GetByCode

func (s *BunTokenStore) GetByCode(ctx context.Context, code string) (oauth2.TokenInfo, error)

func (*BunTokenStore) GetByRefresh

func (s *BunTokenStore) GetByRefresh(ctx context.Context, refresh string) (oauth2.TokenInfo, error)

func (*BunTokenStore) GetClientByCode

func (s *BunTokenStore) GetClientByCode(ctx context.Context, code string) (clientID, userID, redirectURI, scope string, err error)

func (*BunTokenStore) GetPKCEByCode

func (s *BunTokenStore) GetPKCEByCode(ctx context.Context, code string) (codeChallenge, codeChallengeMethod string, err error)

func (*BunTokenStore) RemoveByAccess

func (s *BunTokenStore) RemoveByAccess(ctx context.Context, access string) error

func (*BunTokenStore) RemoveByCode

func (s *BunTokenStore) RemoveByCode(ctx context.Context, code string) error

func (*BunTokenStore) RemoveByRefresh

func (s *BunTokenStore) RemoveByRefresh(ctx context.Context, refresh string) error

func (*BunTokenStore) UpdateCodeToToken

func (s *BunTokenStore) UpdateCodeToToken(ctx context.Context, code string, info oauth2.TokenInfo) error

type Config

type Config struct {
	Issuer               string
	AuthCodeExpiry       time.Duration
	AccessTokenExpiry    time.Duration
	RefreshTokenExpiry   time.Duration
	AllowedResponseTypes []oauth2.ResponseType
	AllowedGrantTypes    []oauth2.GrantType
}

func DefaultConfig

func DefaultConfig(issuer string) Config

type OAuthClient

type OAuthClient struct {
	bun.BaseModel `bun:"table:oauth_clients"`

	ID           string               `bun:"id,pk"`
	SecretHash   []byte               `bun:"secret_hash"`
	Name         string               `bun:"name,notnull"`
	RedirectURIs string               `bun:"redirect_uris,notnull"`
	UserID       *model_db.BinaryUUID `bun:"user_id"`
	CreatedAt    time.Time            `bun:"created_at,nullzero,notnull"`
}

type OAuthToken

type OAuthToken struct {
	bun.BaseModel `bun:"table:oauth_tokens"`

	Code                string              `bun:"code,pk"`
	Access              string              `bun:"access"`
	Refresh             string              `bun:"refresh"`
	ClientID            string              `bun:"client_id,notnull"`
	UserID              model_db.BinaryUUID `bun:"user_id,notnull"`
	RedirectURI         string              `bun:"redirect_uri"`
	Scope               string              `bun:"scope"`
	CodeChallenge       string              `bun:"code_challenge"`
	CodeChallengeMethod string              `bun:"code_challenge_method"`
	CodeExpiresAt       *time.Time          `bun:"code_expires_at"`
	AccessExpiresAt     *time.Time          `bun:"access_expires_at"`
	RefreshExpiresAt    *time.Time          `bun:"refresh_expires_at"`
	CreatedAt           time.Time           `bun:"created_at,nullzero,notnull"`
}

type RegisterClientRequest

type RegisterClientRequest struct {
	ClientName   string   `json:"client_name"`
	RedirectURIs []string `json:"redirect_uris"`
}

type RegisterClientResponse

type RegisterClientResponse struct {
	ClientID     string   `json:"client_id"`
	ClientName   string   `json:"client_name"`
	RedirectURIs []string `json:"redirect_uris"`
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(db *bun.DB, issuer string) *Server

func (*Server) AuthorizeHandler

func (s *Server) AuthorizeHandler(c echo.Context) error

func (*Server) AuthorizePageHandler

func (s *Server) AuthorizePageHandler(c echo.Context) error

func (*Server) BearerAuthMiddleware

func (s *Server) BearerAuthMiddleware() echo.MiddlewareFunc

func (*Server) GetClientStore

func (s *Server) GetClientStore() *BunClientStore

func (*Server) GetConfig

func (s *Server) GetConfig() Config

func (*Server) GetManager

func (s *Server) GetManager() *manage.Manager

func (*Server) GetServer

func (s *Server) GetServer() *server.Server

func (*Server) GetTokenStore

func (s *Server) GetTokenStore() *BunTokenStore

func (*Server) Metadata

func (s *Server) Metadata() map[string]any

func (*Server) MetadataHandler

func (s *Server) MetadataHandler(c echo.Context) error

func (*Server) RegisterClient

func (s *Server) RegisterClient(ctx context.Context, req RegisterClientRequest) (*RegisterClientResponse, error)

func (*Server) RegisterHandler

func (s *Server) RegisterHandler(c echo.Context) error

func (*Server) TokenHandler

func (s *Server) TokenHandler(c echo.Context) error

Jump to

Keyboard shortcuts

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