storage

package module
v0.0.0-...-30833f4 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2021 License: MIT Imports: 4 Imported by: 0

README

osin-storage

OSIN GORM storage

This package implements the storage for OSIN using GORM.

Installation

go get github.com/collinsss/osin-storage

Usage

Please see example

Author

Collinsss

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Access

type Access struct {
	ClientID     string    // Client information
	Authorize    string    // Authorize data, for authorization code
	PrvAccess    string    // Previous access data, for refresh token
	AccessToken  string    `gorm:"primary_key"` // Access token
	RefreshToken string    // Refresh Token. Can be blank
	ExpiresIn    int32     // Token expiration in seconds
	Scope        string    // Requested scope
	RedirectUri  string    // Redirect Uri from request
	CreatedAt    time.Time // Date created
	UserData     string    // Data to be passed to storage. Not used by the library.
}

Access data model

func (Access) TableName

func (Access) TableName(db *gorm.DB) string

TableName is used by `gorm`

type Authorize

type Authorize struct {
	ClientID            string    // Client information
	Code                string    `gorm:"primary_key"` // Authorization code
	ExpiresIn           int32     // Token expiration in seconds
	Scope               string    // Requested scope
	RedirectUri         string    // Redirect Uri from request
	State               string    // State data from request
	CreatedAt           time.Time // Date created
	UserData            string    // Data to be passed to storage. Not used by the library.
	CodeChallenge       string    // Optional code_challenge as described in rfc7636
	CodeChallengeMethod string    // Optional code_challenge_method as described in rfc7636
}

Authorize data model

func (Authorize) TableName

func (Authorize) TableName(db *gorm.DB) string

TableName is used by `gorm`

type Client

type Client struct {
	ID          string `gorm:"primary_key"`
	Secret      string
	RedirectUri string
	UserData    string
}

Client model

func (Client) TableName

func (Client) TableName(db *gorm.DB) string

TableName is used by `gorm`

type Storage

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

func NewStorage

func NewStorage(db *gorm.DB) *Storage

func (*Storage) Clone

func (s *Storage) Clone() osin.Storage

Clone the storage if needed. For example, using mgo, you can clone the session with session.Clone to avoid concurrent access problems. This is to avoid cloning the connection at each method access. Can return itself if not a problem.

func (*Storage) Close

func (s *Storage) Close()

Close the resources the Storage potentially holds (using Clone for example)

func (*Storage) GetClient

func (s *Storage) GetClient(id string) (osin.Client, error)

GetClient loads the client by id (client_id)

func (*Storage) LoadAccess

func (s *Storage) LoadAccess(code string) (*osin.AccessData, error)

LoadAccess retrieves access data by token. Client information MUST be loaded together. AuthorizeData and AccessData DON'T NEED to be loaded if not easily available. Optionally can return error if expired.

func (*Storage) LoadAuthorize

func (s *Storage) LoadAuthorize(code string) (*osin.AuthorizeData, error)

LoadAuthorize looks up AuthorizeData by a code. Client information MUST be loaded together. Optionally can return error if expired.

func (*Storage) LoadRefresh

func (s *Storage) LoadRefresh(code string) (*osin.AccessData, error)

LoadRefresh retrieves refresh AccessData. Client information MUST be loaded together. AuthorizeData and AccessData DON'T NEED to be loaded if not easily available. Optionally can return error if expired.

func (*Storage) RemoveAccess

func (s *Storage) RemoveAccess(code string) error

RemoveAccess revokes or deletes an AccessData.

func (*Storage) RemoveAuthorize

func (s *Storage) RemoveAuthorize(code string) error

RemoveAuthorize revokes or deletes the authorization code.

func (*Storage) RemoveClient

func (s *Storage) RemoveClient(id string) error

RemoveClient removes the client with matching id

func (*Storage) RemoveRefresh

func (s *Storage) RemoveRefresh(code string) error

RemoveRefresh revokes or deletes refresh AccessData.

func (*Storage) SaveAccess

func (s *Storage) SaveAccess(data *osin.AccessData) error

SaveAccess writes AccessData. If RefreshToken is not blank, it must save in a way that can be loaded using LoadRefresh.

func (*Storage) SaveAuthorize

func (s *Storage) SaveAuthorize(data *osin.AuthorizeData) error

SaveAuthorize saves authorize data.

func (*Storage) SaveClient

func (s *Storage) SaveClient(c osin.Client) error

SaveClient saves client

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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