oauth2gorm

package module
v0.0.0-...-10e1fbb Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2021 License: MIT Imports: 15 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(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 {
	gorm.Model

	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