data

package
v0.0.0-...-3a2841b Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoLogin = errors.New("no login exists")
View Source
var ErrUnknownCodeChallengeMethod = errors.New("code_challenge_method is not understood")

Functions

func ParseClientID

func ParseClientID(u string) string

func ParseProfileURL

func ParseProfileURL(u string) string

Types

type Client

type Client struct {
	ID          string
	RedirectURI string
	Name        string
	UpdatedAt   time.Time
	// contains filtered or unexported fields
}

Client stores an app's information, so it doesn't have to be queried again. If redirectURI no longer matches then the data is invalidated.

func (Client) Expired

func (c Client) Expired() bool

type Code

type Code struct {
	Code                string
	ResponseType        string
	Me                  string
	ClientID            string
	RedirectURI         string
	CodeChallenge       string
	CodeChallengeMethod string
	Scope               string
	CreatedAt           time.Time
	ExpiresAt           time.Time
}

func (Code) Expired

func (c Code) Expired() bool

Expired returns true if the Code was created over 60 seconds ago.

func (Code) VerifyChallenge

func (c Code) VerifyChallenge(verifier string) (bool, error)

type Database

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

func Open

func Open(path string, httpClient *http.Client, cookies sessions.Store, expiry Expiry) (*Database, error)

func (*Database) CacheProfile

func (d *Database) CacheProfile(profile Profile) error

func (*Database) Client

func (d *Database) Client(clientID, redirectURI string) (Client, error)

func (*Database) Close

func (d *Database) Close() error

func (*Database) Code

func (d *Database) Code(c string) (code Code, err error)

func (*Database) CreateCode

func (d *Database) CreateCode(me, code string, createdAt time.Time) error

func (*Database) CreateSession

func (d *Database) CreateSession(session Session) error

func (*Database) CreateToken

func (d *Database) CreateToken(token Token) error

func (*Database) Forget

func (d *Database) Forget(me string) error

func (*Database) Login

func (d *Database) Login(r *http.Request) (string, error)

Login returns a user's profile URL (i.e. 'me' value), if they have recently logged in with relme-auth.

func (*Database) Profile

func (d *Database) Profile(me string) (Profile, error)

func (*Database) RevokeClient

func (d *Database) RevokeClient(me, clientID string) error

func (*Database) RevokeToken

func (d *Database) RevokeToken(shortToken string) error

func (*Database) SaveLogin

func (d *Database) SaveLogin(w http.ResponseWriter, r *http.Request, me string) error

func (*Database) Session

func (d *Database) Session(me string) (session Session, err error)

func (*Database) SetProvider

func (d *Database) SetProvider(me, provider, profileURI string) error

func (*Database) Token

func (d *Database) Token(t string) (token Token, err error)

func (*Database) Tokens

func (d *Database) Tokens(me string) (tokens []Token, err error)

type Expiry

type Expiry struct {
	// Session specifies how long a session should be valid for. This is the time
	// from the start of authentication (being served the "choose" page), and
	// hitting the callback from an auth provider.
	Session time.Duration

	// Code specifies how long a code should be valid for. This is the time
	// between hitting the callback from an auth provider, and the client
	// verifying the code.
	Code time.Duration

	// Client specifies how long to store information about a client. It has no
	// influence on the authentication session, but outdated information may be
	// misleading.
	Client time.Duration

	// Profile specifies how long to store the authentication methods for a
	// user. This data can be manually refreshed on the "choose" page.
	Profile time.Duration

	// Login specifies how long to consider the user logged in to relme-auth. If a
	// un-expired login is found a user will be presented with the option to
	// "continue" on the "choose" page, bypassing the need to reauthenticate with
	// a downstream provider.
	Login time.Duration
}

type Login

type Login struct {
	ID        string
	Me        string
	CreatedAt time.Time
	// contains filtered or unexported fields
}

func (Login) Expired

func (l Login) Expired() bool

type Method

type Method struct {
	Provider string
	Profile  string
}

Method is a way a user can authenticate, it contains the name of a 3rd party provider and the expected profile URL with that provider.

type Profile

type Profile struct {
	Me        string
	UpdatedAt time.Time

	Methods []Method
	// contains filtered or unexported fields
}

Profile stores a user's authentication methods, so they don't have to be queried again.

func (Profile) Expired

func (p Profile) Expired() bool

type Session

type Session struct {
	ResponseType        string
	Me                  string
	Provider            string
	ProfileURI          string
	ClientID            string
	RedirectURI         string
	CodeChallenge       string
	CodeChallengeMethod string
	Scope               string
	State               string
	CreatedAt           time.Time
	ExpiresAt           time.Time
}

Session contains all of the information needed to keep track of OAuth requests/responses with a 3rd party.

func (Session) Expired

func (s Session) Expired() bool

type StrategyStore

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

func Strategy

func Strategy(name string) (*StrategyStore, error)

func (*StrategyStore) Claim

func (s *StrategyStore) Claim(key string) (value interface{}, ok bool)

func (*StrategyStore) Insert

func (s *StrategyStore) Insert(value interface{}) (state string, err error)

func (*StrategyStore) Set

func (s *StrategyStore) Set(key string, value interface{}) error

type Token

type Token struct {
	ShortToken    string
	LongTokenHash string
	Me            string
	ClientID      string
	Scope         string
	CreatedAt     time.Time
}

func NewToken

func NewToken(generator func(int) (string, error), code Code) (Token, string, error)

Jump to

Keyboard shortcuts

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