oauth2xorm

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2021 License: MIT Imports: 10 Imported by: 0

README

XORM (MySQL) Storage for OAuth 2.0 v4

Credits

Client storage Based on go-oauth2/mysql
Token storage Based on https://github.com/imrenagi/go-oauth2-mysql

MIT License

Copyright (c) 2018 Lyric

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientStore

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

func NewClientStore

func NewClientStore(db *xorm.Engine, options ...ClientStoreOption) (*ClientStore, error)

NewClientStore creates xorm mysql store instance

func (*ClientStore) Create

func (s *ClientStore) Create(info oauth2.ClientInfo) error

Create creates and stores the new client information

func (*ClientStore) GetByID

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

GetByID retrieves and returns client information by id

type ClientStoreItem

type ClientStoreItem struct {
	ID     string `xorm:"id"`
	Secret string `xorm:"secret"`
	Domain string `xorm:"domain"`
	Data   string `xorm:"data"`
}

ClientStoreItem data item

type ClientStoreOption

type ClientStoreOption func(s *ClientStore)

ClientStoreOption is the configuration options type for client store

func WithClientStoreInitTableDisabled

func WithClientStoreInitTableDisabled() ClientStoreOption

WithClientStoreInitTableDisabled returns option that disables table creation on client store instantiation

func WithClientStoreTableName

func WithClientStoreTableName(tableName string) ClientStoreOption

WithClientStoreTableName returns option that sets client store table name

type Config

type Config struct {
	DSN          string
	MaxLifetime  time.Duration
	MaxOpenConns int
	MaxIdleConns int
}

Config mysql configuration

func NewConfig

func NewConfig(dsn string) *Config

NewConfig create mysql configuration instance

type Store

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

Store mysql token store

func NewDefaultStore

func NewDefaultStore(config *Config, autoMigrate bool) *Store

NewDefaultStore create mysql store instance

func NewStore

func NewStore(config *Config, tableName string, gcInterval int, autoMigrate bool) *Store

NewStore create mysql store instance, config mysql configuration, tableName table name (default oauth2_token), GC time interval (in seconds, default 600)

func NewStoreWithDB

func NewStoreWithDB(db *xorm.Engine, tableName string, gcInterval int, autoMigrate bool) *Store

NewStoreWithDB create mysql store instance, db sql.DB, tableName table name (default oauth2_token), GC time interval (in seconds, default 600)

func (*Store) Close

func (s *Store) Close()

Close close the store

func (*Store) Create

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

Create create and store the new token information

func (*Store) GetByAccess

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

GetByAccess use the access token for token information data

func (*Store) GetByCode

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

GetByCode use the authorization code for token information data

func (*Store) GetByRefresh

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

GetByRefresh use the refresh token for token information data

func (*Store) RemoveByAccess

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

RemoveByAccess use the access token to delete the token information

func (*Store) RemoveByCode

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

RemoveByCode delete the authorization code

func (*Store) RemoveByRefresh

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

RemoveByRefresh use the refresh token to delete the token information

func (*Store) SetStdout

func (s *Store) SetStdout(stdout io.Writer) *Store

SetStdout set error output

type StoreItem

type StoreItem struct {
	ID        int64  `xorm:"id"`
	ExpiredAt int64  `xorm:"expired_at"`
	Code      string `xorm:"code"`
	Access    string `xorm:"access"`
	Refresh   string `xorm:"refresh"`
	Data      string `xorm:"data"`
}

StoreItem data item

Jump to

Keyboard shortcuts

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