redis

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2018 License: MIT Imports: 8 Imported by: 0

README

Redis Storage for OAuth 2.0

Based on the redis token storage

License ReportCard GoDoc

Install

$ go get -u -v gopkg.in/go-oauth2/redis.v1

Usage

package main

import (
	"gopkg.in/go-oauth2/redis.v1"
	"gopkg.in/oauth2.v3/manage"
)

func main() {
	manager := manage.NewDefaultManager()
	// use redis token store
	manager.MustTokenStorage(redis.NewTokenStore(&redis.Config{
		Addr: "127.0.0.1:6379",
	}))

	// ...
}

MIT License

Copyright (c) 2016 Lyric

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTokenStore

func NewTokenStore(cfg *Config) (ts oauth2.TokenStore, err error)

NewTokenStore Create a token store instance based on redis

Types

type Config

type Config struct {
	// The network type, either tcp or unix.
	// Default is tcp.
	Network string
	// host:port address.
	Addr string

	// Dialer creates new network connection and has priority over
	// Network and Addr options.
	Dialer func() (net.Conn, error)

	// Optional password. Must match the password specified in the
	// requirepass server configuration option.
	Password string
	// Database to be selected after connecting to the server.
	DB int

	// Maximum number of retries before giving up.
	// Default is to not retry failed commands.
	MaxRetries int
	// Minimum backoff between each retry.
	// Default is 8 milliseconds; -1 disables backoff.
	MinRetryBackoff time.Duration
	// Maximum backoff between each retry.
	// Default is 512 milliseconds; -1 disables backoff.
	MaxRetryBackoff time.Duration

	// Dial timeout for establishing new connections.
	// Default is 5 seconds.
	DialTimeout time.Duration
	// Timeout for socket reads. If reached, commands will fail
	// with a timeout instead of blocking.
	// Default is 3 seconds.
	ReadTimeout time.Duration
	// Timeout for socket writes. If reached, commands will fail
	// with a timeout instead of blocking.
	// Default is ReadTimeout.
	WriteTimeout time.Duration

	// Maximum number of socket connections.
	// Default is 10 connections per every CPU as reported by runtime.NumCPU.
	PoolSize int
	// Amount of time client waits for connection if all connections
	// are busy before returning an error.
	// Default is ReadTimeout + 1 second.
	PoolTimeout time.Duration
	// Amount of time after which client closes idle connections.
	// Should be less than server's timeout.
	// Default is 5 minutes.
	IdleTimeout time.Duration
	// Frequency of idle checks.
	// Default is 1 minute.
	// When minus value is set, then idle check is disabled.
	IdleCheckFrequency time.Duration

	// TLS Config to use. When set TLS will be negotiated.
	TLSConfig *tls.Config
}

Config Redis parameter options

type TokenStore

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

TokenStore redis token store

func (*TokenStore) Create

func (rs *TokenStore) Create(info oauth2.TokenInfo) (err error)

Create Create and store the new token information

func (*TokenStore) GetByAccess

func (rs *TokenStore) GetByAccess(access string) (ti oauth2.TokenInfo, err error)

GetByAccess Use the access token for token information data

func (*TokenStore) GetByCode

func (rs *TokenStore) GetByCode(code string) (ti oauth2.TokenInfo, err error)

GetByCode Use the authorization code for token information data

func (*TokenStore) GetByRefresh

func (rs *TokenStore) GetByRefresh(refresh string) (ti oauth2.TokenInfo, err error)

GetByRefresh Use the refresh token for token information data

func (*TokenStore) RemoveByAccess

func (rs *TokenStore) RemoveByAccess(access string) (err error)

RemoveByAccess Use the access token to delete the token information

func (*TokenStore) RemoveByCode

func (rs *TokenStore) RemoveByCode(code string) (err error)

RemoveByCode Use the authorization code to delete the token information

func (*TokenStore) RemoveByRefresh

func (rs *TokenStore) RemoveByRefresh(refresh string) (err error)

RemoveByRefresh Use the refresh token to delete the token information

Jump to

Keyboard shortcuts

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