gooauth2gorm

package module
v0.0.0-...-1a88801 Latest Latest
Warning

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

Go to latest
Published: May 11, 2022 License: MIT Imports: 14 Imported by: 0

README

go-oauth2-gorm

https://github.com/go-oauth2/oauth2 store implementation with gorm

Launch test

go test -timeout 60s

Credits

Implementation based on some existing drivers https://github.com/rainlay/go-oauth2-xorm, https://github.com/imrenagi/go-oauth2-mysql and https://github.com/techknowlogick/go-oauth2-gorm

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	ID        string `gorm:"primaryKey"`
	Secret    string
	Domain    string
	Data      string
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt `gorm:"index"`
}

type ClientStore

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

func NewClientStore

func NewClientStore(cfg *Config, table string) *ClientStore

func NewClientStoreWithDB

func NewClientStoreWithDB(cfg *Config, db *gorm.DB, table string) *ClientStore

func (*ClientStore) Create

func (cs *ClientStore) Create(ctx context.Context, info oauth2.ClientInfo) error

Create create oauth2 client

func (*ClientStore) GetByID

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

GetByID retrieves and returns client information by id

func (*ClientStore) RemoveByID

func (ts *ClientStore) RemoveByID(ctx context.Context, id string) error

RemoveByID delete the client by id

type Config

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

type DBType

type DBType int
const (
	PostgresSQL DBType = iota
	MySQL
	SQLite
	SQLServer
	Clickhouse
)

type Token

type Token struct {
	gorm.Model
	ExpiredAt int64
	Code      string
	Access    string
	Refresh   string
	Data      string
}

type TokenStore

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

func NewTokenStore

func NewTokenStore(cfg *Config, table string, gcInterval int) *TokenStore

func NewTokenStoreWithDB

func NewTokenStoreWithDB(cfg *Config, db *gorm.DB, table string, gcInterval int) *TokenStore

func (*TokenStore) Close

func (ts *TokenStore) Close()

Close close the store

func (TokenStore) Create

func (ts TokenStore) Create(ctx context.Context, info oauth2.TokenInfo) error

func (*TokenStore) GetByAccess

func (ts *TokenStore) GetByAccess(ctx context.Context, access string) (oauth2.TokenInfo, error)

GetByAccess use the access token for token information data

func (*TokenStore) GetByCode

func (ts *TokenStore) GetByCode(ctx context.Context, code string) (oauth2.TokenInfo, error)

use the authorization code for token information data

func (*TokenStore) GetByRefresh

func (ts *TokenStore) GetByRefresh(ctx context.Context, refresh string) (oauth2.TokenInfo, error)

GetByRefresh use the refresh token for token information data

func (*TokenStore) RemoveByAccess

func (ts *TokenStore) RemoveByAccess(ctx context.Context, access string) error

use the access token to delete the token information

func (*TokenStore) RemoveByCode

func (ts *TokenStore) RemoveByCode(ctx context.Context, code string) error

delete the authorization code

func (*TokenStore) RemoveByRefresh

func (ts *TokenStore) RemoveByRefresh(ctx context.Context, refresh string) error

use the refresh token to delete the token information

func (*TokenStore) SetStdout

func (ts *TokenStore) SetStdout(stdout io.Writer) *TokenStore

SetStdout set error output

Jump to

Keyboard shortcuts

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