storage

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2022 License: MIT Imports: 7 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAuthorizationCodeRequestEntryExists   = errors.New("authorization code request entry with this ID already exists")
	ErrAuthorizationCodeRequestEntryNotFound = errors.New("authorization code request entry not found")
)
View Source
var (
	ErrClientEntryExists   = errors.New("client entry with this ID already exists")
	ErrClientEntryNotFound = errors.New("client entry not found")
)
View Source
var (
	ErrDeviceCodeRequestEntryExists   = errors.New("DeviceCodeRequest entry with this ID already exists")
	ErrDeviceCodeRequestEntryNotFound = errors.New("DeviceCodeRequest entry not found")
)
View Source
var (
	ErrSessionEntryExists   = errors.New("session entry with this ID already exists")
	ErrSessionEntryNotFound = errors.New("session entry not found")
)
View Source
var (
	ErrTokenEntryExists   = errors.New("token entry with this access string already exists")
	ErrTokenEntryNotFound = errors.New("token entry not found")
)
View Source
var (
	ErrUserEntryExists   = errors.New("user entry with this ID already exists")
	ErrUserEntryNotFound = errors.New("user entry not found")
)

Functions

This section is empty.

Types

type AuthorizationCodeRequest

type AuthorizationCodeRequest struct {
	ClientID            string
	Code                string
	Scope               *Scope
	CodeChallenge       string
	CodeChallengeMethod string
}

func (AuthorizationCodeRequest) GetClientID

func (a AuthorizationCodeRequest) GetClientID() string

func (AuthorizationCodeRequest) GetCode

func (a AuthorizationCodeRequest) GetCode() string

func (AuthorizationCodeRequest) GetCodeChallenge

func (a AuthorizationCodeRequest) GetCodeChallenge() string

func (AuthorizationCodeRequest) GetCodeChallengeMethod

func (a AuthorizationCodeRequest) GetCodeChallengeMethod() string

func (AuthorizationCodeRequest) GetScope

func (a AuthorizationCodeRequest) GetScope() *Scope

func (AuthorizationCodeRequest) SetClientID

func (a AuthorizationCodeRequest) SetClientID(id string)

func (AuthorizationCodeRequest) SetCode

func (a AuthorizationCodeRequest) SetCode(code string)

func (AuthorizationCodeRequest) SetCodeChallenge

func (a AuthorizationCodeRequest) SetCodeChallenge(challenge string)

func (AuthorizationCodeRequest) SetCodeChallengeMethod

func (a AuthorizationCodeRequest) SetCodeChallengeMethod(method string)

func (AuthorizationCodeRequest) SetScope

func (a AuthorizationCodeRequest) SetScope(scope *Scope)

type AuthorizationCodeRequestStorage

type AuthorizationCodeRequestStorage interface {
	Pop(string) (OAuth2AuthorizationCodeRequest, error)
	Insert(OAuth2AuthorizationCodeRequest) error
	Close() error
}

AuthorizationCodeRequestStorage stores Authorization code requests. For in-memory implementations, Close() should be a no-op.

type Client

type Client struct {
	ID           string
	Secret       string
	Confidential bool
	AppName      string
	RedirectURLs []string
}

A Client represents an application. A Client's ID must be unique.

func NewClient

func NewClient(id, secret, appName string) Client

func (Client) AddRedirectURL

func (c Client) AddRedirectURL(u string)

func (Client) ClearRedirectURLS

func (c Client) ClearRedirectURLS()

func (Client) GetApplicationName

func (c Client) GetApplicationName() string

func (Client) GetID

func (c Client) GetID() string

func (Client) GetRedirectURLs added in v0.1.0

func (c Client) GetRedirectURLs() []string

func (Client) GetSecret

func (c Client) GetSecret() string

func (Client) HasRedirectURL

func (c Client) HasRedirectURL(u string) bool

func (Client) IsConfidential

func (c Client) IsConfidential() bool

func (Client) RemoveRedirectURL

func (c Client) RemoveRedirectURL(u string)

func (Client) SetApplicationName

func (c Client) SetApplicationName(appName string)

func (Client) SetConfidential

func (c Client) SetConfidential(b bool)

func (Client) SetID

func (c Client) SetID(id string)

func (Client) SetRedirectURLs added in v0.1.0

func (c Client) SetRedirectURLs(urls []string)

func (Client) SetSecret

func (c Client) SetSecret(s string)

func (Client) String

func (c Client) String() string

type ClientStorage

type ClientStorage interface {
	Get(string) (OAuth2Client, error)
	Add(OAuth2Client) error
	Edit(OAuth2Client) error
	Remove(OAuth2Client) error
	Close() error
}

ClientStorage is the interface that must be implemented to act as a client storage For in-memory implementations, Close() should be a no-op.

type DeviceCodeRequest

type DeviceCodeRequest struct {
	ClientID      string
	Response      DeviceCodeResponse
	TokenResponse Token
}

func (DeviceCodeRequest) GetClientID

func (d DeviceCodeRequest) GetClientID() string

func (DeviceCodeRequest) GetResponse

func (d DeviceCodeRequest) GetResponse() DeviceCodeResponse

func (DeviceCodeRequest) GetTokenResponse

func (d DeviceCodeRequest) GetTokenResponse() Token

func (DeviceCodeRequest) SetClientID

func (d DeviceCodeRequest) SetClientID(id string)

func (DeviceCodeRequest) SetResponse

func (d DeviceCodeRequest) SetResponse(response DeviceCodeResponse)

func (DeviceCodeRequest) SetTokenResponse

func (d DeviceCodeRequest) SetTokenResponse(token Token)

type DeviceCodeRequestStorage

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

func NewMemoryDeviceCodeRequestStorage

func NewMemoryDeviceCodeRequestStorage() *DeviceCodeRequestStorage

func (*DeviceCodeRequestStorage) Add

func (*DeviceCodeRequestStorage) Close

func (dcrs *DeviceCodeRequestStorage) Close() error

func (*DeviceCodeRequestStorage) Find

func (dcrs *DeviceCodeRequestStorage) Find(deviceCode, clientID string) (OAuth2DeviceCodeRequest, error)

func (*DeviceCodeRequestStorage) Get

func (*DeviceCodeRequestStorage) Update

type DeviceCodeResponse

type DeviceCodeResponse struct {
	DeviceCode              string `json:"device_code"`
	UserCode                string `json:"user_code"`
	VerificationURI         string `json:"verification_uri"`
	VerificationURIComplete string `json:"verification_uri_complete"`
	ExpiresIn               uint64 `json:"expires_in"`
	Interval                uint64 `json:"interval"`
}

type DeviceCodeStorage

DeviceCodeStorage stores device codes. For in-memory implementations, Close() should be a no-op.

type MemoryAuthorizationCodeRequestStorage

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

func NewMemoryAuthorizationCodeRequestStorage

func NewMemoryAuthorizationCodeRequestStorage() *MemoryAuthorizationCodeRequestStorage

func (*MemoryAuthorizationCodeRequestStorage) Close

func (*MemoryAuthorizationCodeRequestStorage) Insert

func (*MemoryAuthorizationCodeRequestStorage) Pop

type MemoryClientStorage

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

func NewMemoryClientStorage

func NewMemoryClientStorage() *MemoryClientStorage

func (*MemoryClientStorage) Add

func (cs *MemoryClientStorage) Add(client OAuth2Client) error

func (*MemoryClientStorage) Close

func (_ *MemoryClientStorage) Close() error

func (*MemoryClientStorage) Edit

func (cs *MemoryClientStorage) Edit(client OAuth2Client) error

func (*MemoryClientStorage) Get

func (*MemoryClientStorage) Remove

func (cs *MemoryClientStorage) Remove(client OAuth2Client) error

type MemorySessionStorage

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

func NewMemorySessionStorage

func NewMemorySessionStorage() *MemorySessionStorage

func (*MemorySessionStorage) Add

func (ss *MemorySessionStorage) Add(session OAuth2Session) error

func (*MemorySessionStorage) Close

func (_ *MemorySessionStorage) Close() error

func (*MemorySessionStorage) Get

func (*MemorySessionStorage) Remove

func (ss *MemorySessionStorage) Remove(id string) error

type MemoryTokenStorage

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

func NewMemoryTokenStorage

func NewMemoryTokenStorage() *MemoryTokenStorage

func (*MemoryTokenStorage) Add added in v0.2.0

func (*MemoryTokenStorage) Close

func (_ *MemoryTokenStorage) Close() error

func (*MemoryTokenStorage) FindByAccessToken

func (ts *MemoryTokenStorage) FindByAccessToken(at string) (OAuth2Token, error)

func (*MemoryTokenStorage) FindByCodeChallenge

func (ts *MemoryTokenStorage) FindByCodeChallenge(cc string) (OAuth2Token, error)

func (*MemoryTokenStorage) Remove

func (ts *MemoryTokenStorage) Remove(t OAuth2Token) error

type MemoryUserStorage

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

func NewMemoryUserStorage

func NewMemoryUserStorage() *MemoryUserStorage

func (*MemoryUserStorage) Add

func (us *MemoryUserStorage) Add(user OAuth2User) error

func (*MemoryUserStorage) Close

func (s *MemoryUserStorage) Close() error

func (*MemoryUserStorage) Edit

func (us *MemoryUserStorage) Edit(user OAuth2User) error

func (*MemoryUserStorage) Get

func (us *MemoryUserStorage) Get(id uint) (OAuth2User, error)

func (*MemoryUserStorage) GetByUsername

func (us *MemoryUserStorage) GetByUsername(name string) (OAuth2User, error)

func (*MemoryUserStorage) Remove

func (us *MemoryUserStorage) Remove(id uint) error

type OAuth2AuthorizationCodeRequest

type OAuth2AuthorizationCodeRequest interface {
	GetClientID() string
	SetClientID(string)
	GetCode() string
	SetCode(string)
	GetScope() *Scope
	SetScope(*Scope)
	GetCodeChallenge() string
	SetCodeChallenge(string)
	GetCodeChallengeMethod() string
	SetCodeChallengeMethod(string)
}

type OAuth2Client

type OAuth2Client interface {
	GetID() string
	SetID(string)
	GetSecret() string
	SetSecret(string)
	IsConfidential() bool
	SetConfidential(bool)
	GetApplicationName() string
	SetApplicationName(string)
	HasRedirectURL(string) bool
	AddRedirectURL(string)
	RemoveRedirectURL(string)
	GetRedirectURLs() []string
	SetRedirectURLs([]string)
	ClearRedirectURLS()
}

type OAuth2DeviceCodeRequest

type OAuth2DeviceCodeRequest interface {
	GetClientID() string
	SetClientID(string)
	GetResponse() DeviceCodeResponse
	SetResponse(DeviceCodeResponse)
	GetTokenResponse() Token
	SetTokenResponse(Token)
}

type OAuth2Session

type OAuth2Session interface {
	GetID() string
	SetID(string)
	GetUserID() uint
	SetUserID(uint)
	GetExpires() time.Time
	SetExpires(t time.Time)
}

type OAuth2Token

type OAuth2Token interface {
	GetClientID() string
	SetClientID(string)
	GetAccessToken() string
	SetAccessToken(string)
	GetTokenType() string
	SetTokenType(string)
	GetExpiresIn() uint64
	SetExpiresIn(uint64)
	GetRefreshToken() string
	SetRefreshToken(string)
	GetScope() *Scope
	SetScope(*Scope)
	SetRawScope(s string)
	GetState() string
	SetState(string)
	GetCodeChallenge() string
	SetCodeChallenge(string)
	GetAuthorizationCode() string
	SetAuthorizationCode(string)
}

An OAuth2Token represents the (meta)data related to a successfully executed authorization process. You can use your own implementation or the existing Token{}.

type OAuth2User

type OAuth2User interface {
	GetID() uint
	SetID(uint)
	GetUsername() string
	SetUsername(string)
	GetEmail() string
	SetEmail(string)
	GetPassword() string
	SetPassword(string)
	DoesPasswordMatch(string) bool
	IsDisabled() bool
	SetDisabled(bool)
}

type Scope

type Scope []string

func NewScope added in v0.2.0

func NewScope(raw string) *Scope

func (*Scope) MarshalJSON

func (s *Scope) MarshalJSON() ([]byte, error)

func (*Scope) String

func (s *Scope) String() string

func (*Scope) UnmarshalJSON

func (s *Scope) UnmarshalJSON(d []byte) error

type Session

type Session struct {
	ID      string
	UserID  uint
	Expires time.Time
}

func (Session) GetExpires

func (s Session) GetExpires() time.Time

func (Session) GetID

func (s Session) GetID() string

func (Session) GetUserID

func (s Session) GetUserID() uint

func (Session) SetExpires

func (s Session) SetExpires(t time.Time)

func (Session) SetID

func (s Session) SetID(id string)

func (Session) SetUserID

func (s Session) SetUserID(id uint)

type SessionStorage

type SessionStorage interface {
	Get(string) (OAuth2Session, error)
	Add(OAuth2Session) error
	Remove(string) error
	Close() error
}

A SessionStorage stores sessions and related meta information. For in-memory implementations, Close() should be a no-op.

type Token

type Token struct {
	ClientID          string `json:"-"`
	AccessToken       string `json:"access_token"`
	TokenType         string `json:"token_type"`
	ExpiresIn         uint64 `json:"expires_in"`
	RefreshToken      string `json:"refresh_token,omitempty"`
	Scope             *Scope `json:"scope,omitempty"`
	State             string `json:"state,omitempty"`
	CodeChallenge     string `json:"code_challenge,omitempty"`
	AuthorizationCode string `json:"authorization_code,omitempty"`
}

A Token is a ready-to-use implementation of the OAuth2Token interface.

func (Token) GetAccessToken

func (t Token) GetAccessToken() string

func (Token) GetAuthorizationCode

func (t Token) GetAuthorizationCode() string

func (Token) GetClientID

func (t Token) GetClientID() string

func (Token) GetCodeChallenge

func (t Token) GetCodeChallenge() string

func (Token) GetExpiresIn

func (t Token) GetExpiresIn() uint64

func (Token) GetRefreshToken

func (t Token) GetRefreshToken() string

func (Token) GetScope

func (t Token) GetScope() *Scope

func (Token) GetState

func (t Token) GetState() string

func (Token) GetTokenType

func (t Token) GetTokenType() string

func (Token) SetAccessToken

func (t Token) SetAccessToken(at string)

func (Token) SetAuthorizationCode

func (t Token) SetAuthorizationCode(ac string)

func (Token) SetClientID

func (t Token) SetClientID(id string)

func (Token) SetCodeChallenge

func (t Token) SetCodeChallenge(cc string)

func (Token) SetExpiresIn

func (t Token) SetExpiresIn(ex uint64)

func (Token) SetRawScope

func (t Token) SetRawScope(raw string)

func (Token) SetRefreshToken

func (t Token) SetRefreshToken(rt string)

func (Token) SetScope

func (t Token) SetScope(scope *Scope)

func (Token) SetState

func (t Token) SetState(s string)

func (Token) SetTokenType

func (t Token) SetTokenType(tt string)

type TokenStorage

type TokenStorage interface {
	FindByCodeChallenge(string) (OAuth2Token, error)
	FindByAccessToken(string) (OAuth2Token, error)
	Add(OAuth2Token) error
	Remove(OAuth2Token) error
	Close() error
}

A TokenStorage takes care of storing a supplied token associated with the given client ID. A token must be unique. For in-memory implementations, Close() should be a no-op.

type User

type User struct {
	ID       uint
	Username string
	Email    string
	Password string
	Disabled bool
}

A User represents a resource owner.

func (User) DoesPasswordMatch

func (u User) DoesPasswordMatch(password string) bool

func (User) GetEmail

func (u User) GetEmail() string

func (User) GetID

func (u User) GetID() uint

func (User) GetPassword

func (u User) GetPassword() string

func (User) GetUsername

func (u User) GetUsername() string

func (User) IsDisabled

func (u User) IsDisabled() bool

func (User) SetDisabled

func (u User) SetDisabled(d bool)

func (User) SetEmail

func (u User) SetEmail(email string)

func (User) SetID

func (u User) SetID(id uint)

func (User) SetPassword

func (u User) SetPassword(password string)

func (User) SetUsername

func (u User) SetUsername(username string)

type UserStorage

type UserStorage interface {
	Get(id uint) (OAuth2User, error)
	GetByUsername(name string) (OAuth2User, error)
	Add(user OAuth2User) error
	Edit(user OAuth2User) error
	Remove(id uint) error
	Close() error
}

A UserStorage stores information about users (resource owners). For in-memory implementations, Close() should be a no-op.

Jump to

Keyboard shortcuts

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