auth

package
v0.0.0-...-26e95de Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateClient

func CreateClient(ctx context.Context, clientSecretHash ClientSecretHasher, desc, redirectURL string) (clientID string, clientSecret string, err error)

func NewHandler

func NewHandler(c *Config) http.Handler

func RedirectWhenLoggedInAndAssigned

func RedirectWhenLoggedInAndAssigned(callbackURL string) func(http.Handler) http.Handler

Types

type AccessTokenResponds

type AccessTokenResponds struct {
	AccessToken string  `json:"access_token,omitempty"`
	TokenType   string  `json:"token_type,omitempty"`
	ExpiresIn   int     `json:"expires_in,omitempty"`
	IDToken     IDToken `json:"id_token,omitempty"`
}

type Authorization

type Authorization struct {
	ID                    uint `gorm:"primarykey"`
	CreatedAt             time.Time
	UpdatedAt             time.Time
	InternalClientID      uuid.UUID   `gorm:"column:client_id;type:VARCHAR;size:191;not null"`
	Client                Client      `gorm:"foreignKey:InternalClientID"`
	InternalUserID        *uint       `gorm:"column:user_id"`
	User                  *model.User `gorm:"foreignKey:InternalUserID"`
	InternalState         string      `gorm:"column:state"`
	InternalCode          []byte      `gorm:"column:code;type:BLOB(16)"`
	InternalCodeChallenge string      `gorm:"column:code_challenge;type:BLOB(16)"`
	SessionID             uuid.UUID   `gorm:"column:session_id;type:VARCHAR(191);not null"`
}

func FirstAuthorization

func FirstAuthorization(ctx context.Context) (*Authorization, error)

func (*Authorization) ClientID

func (a *Authorization) ClientID() uuid.UUID

func (*Authorization) Code

func (a *Authorization) Code() string

func (*Authorization) CodeChallenge

func (a *Authorization) CodeChallenge() string

func (*Authorization) Delete

func (a *Authorization) Delete(ctx context.Context) error

func (*Authorization) IDStr

func (a *Authorization) IDStr() string

func (*Authorization) RedirectURI

func (a *Authorization) RedirectURI() string

func (*Authorization) SetUserID

func (a *Authorization) SetUserID(ctx context.Context, userID uint) error

func (*Authorization) State

func (a *Authorization) State() string

func (*Authorization) UserID

func (a *Authorization) UserID() uint

type Client

type Client struct {
	ID                  uuid.UUID `gorm:"primarykey"`
	CreatedAt           time.Time
	UpdatedAt           time.Time
	DeletedAt           gorm.DeletedAt `gorm:"index"`
	Description         string         `gorm:"type:VARCHAR(255);not null"`
	ClientSecret        string         `gorm:"type:VARCHAR(255);not null"`
	InternalRedirectURI string         `gorm:"column:redirect_uri;type:VARCHAR(255);not null"`
}

func (*Client) ClientID

func (c *Client) ClientID() uuid.UUID

func (*Client) RedirectURI

func (c *Client) RedirectURI() string

func (*Client) VerifyClientSecret

func (c *Client) VerifyClientSecret(s string) error

type ClientSecretHasher

type ClientSecretHasher interface {
	Key([]byte) []byte
	// contains filtered or unexported methods
}

func NewClientSecretHasher

func NewClientSecretHasher() ClientSecretHasher

type ClientSecretVerifier

type ClientSecretVerifier interface {
	VerifyClientSecret(string) error
}

type Config

type Config struct {
	IssuerUrl  string
	PrivateKey *ecdsa.PrivateKey
}

type IDToken

type IDToken struct {
	Key       *ecdsa.PrivateKey
	Issuer    string
	ExpiresIn time.Duration
	UserID    uint
	ClientID  uuid.UUID
}

func (IDToken) MarshalText

func (token IDToken) MarshalText() ([]byte, error)

type IdTokenClaims

type IdTokenClaims struct {
	jwt.RegisteredClaims
}

Jump to

Keyboard shortcuts

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