oauth2gorm

package module
v0.0.0-...-7d300ef Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2020 License: MIT Imports: 14 Imported by: 0

README

go-oauth2-gorm

Credits

Based on https://github.com/go-oauth2/mysql/

Feature

Support gorm v2

Documentation

Index

Constants

View Source
const (
	MySQL = iota
	PostgreSQL
	SQLite
	SQLServer
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	DSN         string
	DBType      DBType
	TableName   string
	MaxLifetime time.Duration
}

Config gorm configuration

func NewConfig

func NewConfig(dsn string, dbType DBType, tableName string) *Config

NewConfig create mysql configuration instance

type DBType

type DBType int8

type Store

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

Store mysql token store

func NewStore

func NewStore(config *Config, gcInterval int) *Store

NewStore create mysql store instance,

func NewStoreWithDB

func NewStoreWithDB(config *Config, db *gorm.DB, gcInterval int) *Store

func (*Store) Close

func (s *Store) Close()

Close close the store

func (*Store) Create

func (s *Store) Create(info oauth2.TokenInfo) error

Create create and store the new token information

func (*Store) GetByAccess

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

GetByAccess use the access token for token information data

func (*Store) GetByCode

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

GetByCode use the authorization code for token information data

func (*Store) GetByRefresh

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

GetByRefresh use the refresh token for token information data

func (*Store) RemoveByAccess

func (s *Store) RemoveByAccess(access string) error

RemoveByAccess use the access token to delete the token information

func (*Store) RemoveByCode

func (s *Store) RemoveByCode(code string) error

RemoveByCode delete the authorization code

func (*Store) RemoveByRefresh

func (s *Store) RemoveByRefresh(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 {
	gorm.Model
	//ID        int64 `gorm:"AUTO_INCREMENT"`
	ExpiredAt int64
	Code      string `gorm:"type:varchar(512)"`
	Access    string `gorm:"type:varchar(512)"`
	Refresh   string `gorm:"type:varchar(512)"`
	Data      string `gorm:"type:text"`
}

StoreItem data item

Jump to

Keyboard shortcuts

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