osinredis

package module
v0.0.0-...-13f1e0c Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2018 License: MIT Imports: 7 Imported by: 0

README

Redis storage for osin

Provides Redis-based storage for osin and is based on redigo.

GoDoc

Installation

$ go get github.com/ShaleApps/osinredis

Running tests

The tests are integration tests that require a running Redis instance. Each test runs FLUSHALL on the server so if you don't want to run against the default local address (:6379), provide a different address via a REDIS_ADDR environment variable

$ REDIS_ADDR=:1234 go test ./...

Usage

Example:

import (
    "github.com/RangelReale/osin"
    "github.com/ShaleApps/osinredis"
	"github.com/garyburd/redigo/redis"
)

func main() {
	pool = &redis.Pool{
		Dial: func() (redis.Conn, error) {
			conn, err := redis.Dial("tcp", ":6379")
			if err != nil {
				return nil, err
			}
			return conn, nil
		},
	}

	storage := osinredis.New(pool, "prefix")
	server := osin.NewServer(osin.NewServerConfig(), storage)
}

Documentation

Overview

A Redis storage backend for osin.

Installation:

go get github.com/ShaleApps/osinredis

Usage:

import (
	"github.com/RangelReale/osin"
	"github.com/ShaleApps/osinredis"
	"github.com/garyburd/redigo/redis"
)

func main() {
	pool = &redis.Pool{
		Dial: func() (redis.Conn, error) {
			conn, err := redis.Dial("tcp", ":6379")
			if err != nil {
				return nil, err
			}
			return conn, nil
		},
	}

	storage := osinredis.New(pool, "prefix")
	server := osin.NewServer(osin.NewServerConfig(), storage)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Storage

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

Storage implements "github.com/RangelReale/osin".Storage

func New

func New(pool *redis.Pool, keyPrefix string) *Storage

New initializes and returns a new 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) CreateClient

func (s *Storage) CreateClient(client osin.Client) error

CreateClient inserts a new client

func (*Storage) DeleteClient

func (s *Storage) DeleteClient(client osin.Client) error

DeleteClient deletes given client

func (*Storage) GetClient

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

GetClient gets a client by ID

func (*Storage) LoadAccess

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

LoadAccess gets access data with given access token

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(token string) (*osin.AccessData, error)

LoadRefresh gets access data with given refresh token

func (*Storage) RemoveAccess

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

RemoveAccess deletes AccessData with given access token

func (*Storage) RemoveAuthorize

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

RemoveAuthorize revokes or deletes the authorization code.

func (*Storage) RemoveRefresh

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

RemoveRefresh deletes AccessData with given refresh token

func (*Storage) SaveAccess

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

SaveAccess creates AccessData.

func (*Storage) SaveAuthorize

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

SaveAuthorize saves authorize data.

func (*Storage) UpdateClient

func (s *Storage) UpdateClient(client osin.Client) error

UpdateClient updates a client

Jump to

Keyboard shortcuts

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