storage

package
v0.0.0-...-45d60b1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2015 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultClientSecretCost = 12
View Source
const DefaultPasswordCost = 12

Variables

View Source
var (
	ErrNotUnique = errors.New("duplicate key value violates unique key constraint")
)

Functions

func RandomToken

func RandomToken() (string, error)

Types

type Application

type Application struct {
	Id                 int64  `json:"id"`
	Name               string `json:"name"`
	Description        string `json:"description"`
	Website            string `json:"website"`
	ClientType         string `json:"client_type"`
	ClientId           string `json:"client_id"`
	ClientSecret       string `json:"client_secret,omitempty"`
	HashedClientSecret string `json:"-"`
}

type ApplicationParams

type ApplicationParams struct {
}

type ApplicationsService

type ApplicationsService interface {
	Authorize(a *Application, scope string) (*Token, error)
	ExchangeAuthCode(a *Application, code, redirectUri string) (*Token, error)
	FindByCredentials(email, password string) (*Application, error)
	New(name, description, website, logo, clientType string) (*Application, error)
}

type Client

type Client struct {
	Apps   ApplicationsService
	Tokens TokensService
	Users  UsersService
	// contains filtered or unexported fields
}

func NewClient

func NewClient(cfg *Config) (*Client, error)

func (*Client) Close

func (c *Client) Close() error

type Config

type Config struct {
	Database DatabaseConfig
}

type Database

type Database interface {
	Close() error
	Begin() (Tx, error)

	Exec(query string, args ...interface{}) (sql.Result, error)
	Get(dest interface{}, query string, args ...interface{}) error
	QueryRow(query string, args ...interface{}) *sql.Row
	Rebind(query string) string
	Select(dest interface{}, query string, args ...interface{}) error
}

func NewDatabase

func NewDatabase(db *sqlx.DB) Database

type DatabaseConfig

type DatabaseConfig struct {
	User     string
	Password string
	Protocol string
	Host     string
	Port     int
	Database string
	Sslmode  string
	Pool     int
}

type LocalApplicationsService

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

func (*LocalApplicationsService) Authorize

func (s *LocalApplicationsService) Authorize(a *Application, scope string) (*Token, error)

func (*LocalApplicationsService) ExchangeAuthCode

func (s *LocalApplicationsService) ExchangeAuthCode(a *Application, code, redirectUri string) (*Token, error)

func (*LocalApplicationsService) FindByClientId

func (s *LocalApplicationsService) FindByClientId(id string) (*Application, error)

func (*LocalApplicationsService) FindByCredentials

func (s *LocalApplicationsService) FindByCredentials(id, secret string) (*Application, error)

func (*LocalApplicationsService) New

func (s *LocalApplicationsService) New(name, description, website, logo, clientType string) (*Application, error)

type LocalTokensService

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

func (*LocalTokensService) FindById

func (s *LocalTokensService) FindById(userId, labelId int64) (*Token, error)

func (*LocalTokensService) New

func (s *LocalTokensService) New(userId int64, params *TokenParams) (*Token, error)

type LocalUsersService

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

func (*LocalUsersService) Authorize

func (s *LocalUsersService) Authorize(userId, clientId int64, scope string, refresh bool) (string, error)

func (*LocalUsersService) FindByCredentials

func (s *LocalUsersService) FindByCredentials(email, password string) (u *User, err error)

func (*LocalUsersService) FindByEmail

func (s *LocalUsersService) FindByEmail(email string) (u *User, err error)

func (*LocalUsersService) FindByRefreshToken

func (s *LocalUsersService) FindByRefreshToken(clientId int64, token string) (u *User, err error)

func (*LocalUsersService) FindByToken

func (s *LocalUsersService) FindByToken(token string) (u *User, err error)

func (*LocalUsersService) New

func (s *LocalUsersService) New(params *UserParams) (*User, error)

type SqlxDatabase

type SqlxDatabase struct {
	*sqlx.DB
}

func (*SqlxDatabase) Begin

func (db *SqlxDatabase) Begin() (Tx, error)

type SqlxTx

type SqlxTx struct {
	*sqlx.Tx
}

type Token

type Token struct {
	Id        int
	ClientId  int
	UserId    int
	Type      string
	Token     string
	ExpiresAt time.Time
}

type TokenParams

type TokenParams struct {
}

type TokensService

type TokensService interface {
	FindById(userId, labelId int64) (*Token, error)
	New(userId int64, params *TokenParams) (*Token, error)
}

type Tx

type Tx interface {
	Commit() error
	Exec(query string, args ...interface{}) (sql.Result, error)
	Get(dest interface{}, query string, args ...interface{}) error
	QueryRow(query string, args ...interface{}) *sql.Row
	Select(dest interface{}, query string, args ...interface{}) error
	Rollback() error
}

type User

type User struct {
	Id    int64  `json:"id"`
	Email string `json:"email"`
}

type UserParams

type UserParams struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

type UsersService

type UsersService interface {
	FindByCredentials(email, password string) (*User, error)
	FindByEmail(email string) (*User, error)
	FindByToken(token string) (*User, error)
	FindByRefreshToken(clientId int64, token string) (*User, error)
	New(params *UserParams) (*User, error)
	Authorize(userId, clientId int64, scope string, refresh bool) (string, error)
}

Jump to

Keyboard shortcuts

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