redis

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2019 License: MIT Imports: 8 Imported by: 0

README

Redis Storage for OAuth 2.0

forked from go-oauth2/redis, supported get by user id and remove by user id.

Install

$ go get -u -v github.com/Ankr-network/oauth2-redis

Usage

package main

import (
	"github.com/go-redis/redis"
	oredis "github.com/Ankr-network/oauth2-redis"
	"gopkg.in/oauth2.v3/manage"
)

func main() {
	manager := manage.NewDefaultManager()
	
	tokenStore := oredis.NewRedisStore(&redis.Options{
		Addr: "127.0.0.1:6379",
		DB: 15,
	})
	// use redis token store
	manager.MapTokenStorage(tokenStore)

	// get token by user id
	// t, _ := tokenStore.GetByUID("test") // get token info by user id
	// _ := tokenStore.RemoveByUID("test") // remove access token and refresh token by uid

	// use redis cluster store
	// manager.MapTokenStorage(oredis.NewRedisClusterStore(&redis.ClusterOptions{
	// 	Addrs: []string{"127.0.0.1:6379"},
	// 	DB: 15,
	// }))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExtendedTokenStore

type ExtendedTokenStore interface {
	GetByUID(uid string) ([]oauth2.TokenInfo, error)
	RemoveByUID(uid string) error
	GetBlacklist() auth.Blacklist
	oauth2.TokenStore
}

type TokenStore

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

TokenStore redis token store

func NewRedisClusterStore

func NewRedisClusterStore(opts *redis.ClusterOptions, keyNamespace ...string) *TokenStore

NewRedisClusterStore create an instance of a redis cluster store

func NewRedisClusterStoreWithCli

func NewRedisClusterStoreWithCli(cli *redis.ClusterClient, keyNamespace ...string) *TokenStore

NewRedisClusterStoreWithCli create an instance of a redis cluster store

func NewRedisStore

func NewRedisStore(opts *redis.Options, keyNamespace ...string) *TokenStore

NewRedisStore create an instance of a redis store

func NewRedisStoreWithCli

func NewRedisStoreWithCli(cli *redis.Client, keyNamespace ...string) *TokenStore

NewRedisStoreWithCli create an instance of a redis store

func (*TokenStore) Close

func (s *TokenStore) Close() error

Close close the store

func (*TokenStore) Create

func (s *TokenStore) Create(info oauth2.TokenInfo) error

Create Create and store the new token information

func (*TokenStore) GetBlacklist added in v1.1.0

func (s *TokenStore) GetBlacklist() auth.Blacklist

func (*TokenStore) GetByAccess

func (s *TokenStore) GetByAccess(access string) (oauth2.TokenInfo, error)

GetByAccess Use the access token for token information data

func (*TokenStore) GetByCode

func (s *TokenStore) GetByCode(code string) (oauth2.TokenInfo, error)

GetByCode Use the authorization code for token information data

func (*TokenStore) GetByRefresh

func (s *TokenStore) GetByRefresh(refresh string) (oauth2.TokenInfo, error)

GetByRefresh Use the refresh token for token information data

func (*TokenStore) GetByUID

func (s *TokenStore) GetByUID(uid string) ([]oauth2.TokenInfo, error)

GetByUID Use the user id for token information data

func (*TokenStore) RemoveByAccess

func (s *TokenStore) RemoveByAccess(access string) error

RemoveByAccess Use the access token to delete the token information

func (*TokenStore) RemoveByCode

func (s *TokenStore) RemoveByCode(code string) error

RemoveByCode Use the authorization code to delete the token information

func (*TokenStore) RemoveByRefresh

func (s *TokenStore) RemoveByRefresh(refresh string) error

RemoveByRefresh Use the refresh token to delete the token information

func (*TokenStore) RemoveByUID

func (s *TokenStore) RemoveByUID(uid string) error

RemoveByUID Use the user id to delete the token information

Jump to

Keyboard shortcuts

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