couchdb

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2022 License: MIT Imports: 7 Imported by: 0

README

CouchDB Storage for OAuth 2.0

Install

$ go get github.com/DataChassis/go-oauth2-couchdb

Usage

package main

import (
	couchdb "github.com/DataChassis/go-oauth2-couchdb"
	"github.com/go-oauth2/oauth2/manage"
)

func main() {
	manager := manage.NewDefaultManager()

	// use couchdb token store
	tokenConfig := couchdb.NewConfig("http://localhost:5984", "oauth2-tokens", "username", "password")
	manager.MapTokenStorage(couchdb.NewTokenStore(tokenConfig))

	// use couchdb client store
	clientConfig := couchdb.NewConfig("http://localhost:5984", "oauth2-clients", "username", "password")
	manager.MapClientStorage(couchdb.NewClientStore(clientConfig))

	// ...
}

MIT License

Copyright (c) 2022 Data Chassis Ltd
Portions Copyright (c) 2016 Lyric

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientConfig

type ClientConfig struct {
	// store clients data collection name
	ClientsCName string
}

ClientConfig client configuration parameters

func NewDefaultClientConfig

func NewDefaultClientConfig() *ClientConfig

NewDefaultClientConfig create a default client configuration

type ClientStore

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

ClientStore CouchDB storage for OAuth 2.0

func NewClientStore

func NewClientStore(cfg *Config, ccfgs ...*ClientConfig) *ClientStore

NewClientStore create a client store instance based on mongodb

func NewClientStoreWithSession

func NewClientStoreWithSession(session *kivik.Client, dbName string, ccfgs ...*ClientConfig) *ClientStore

NewClientStoreWithSession create a client store instance based on mongodb

func (*ClientStore) GetByID

func (cs *ClientStore) GetByID(id string) (info oauth2.ClientInfo, err error)

GetByID according to the ID for the client information

func (*ClientStore) RemoveByID

func (cs *ClientStore) RemoveByID(id string) (err error)

RemoveByID use the client id to delete the client information

func (*ClientStore) Set

func (cs *ClientStore) Set(info oauth2.ClientInfo) (err error)

Set set client information

type Config

type Config struct {
	URL      string
	DB       string
	Username string
	Password string
}

Config mongodb configuration parameters

func NewConfig

func NewConfig(url, db string, username string, password string) *Config

NewConfig create mongodb configuration

type TokenConfig

type TokenConfig struct {
	// store token based data collection name
	BasicCName string
}

TokenConfig token configuration parameters

func NewDefaultTokenConfig

func NewDefaultTokenConfig() *TokenConfig

NewDefaultTokenConfig create a default token configuration

type TokenStore

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

TokenStore CouchDB storage for OAuth 2.0

func NewTokenStore

func NewTokenStore(cfg *Config, tcfgs ...*TokenConfig) (store *TokenStore)

NewTokenStore create a token store instance based on mongodb

func NewTokenStoreWithSession

func NewTokenStoreWithSession(session *kivik.Client, dbName string, tcfgs ...*TokenConfig) (store *TokenStore)

NewTokenStoreWithSession create a token store instance based on mongodb

func (*TokenStore) Close

func (ts *TokenStore) Close()

Close close the couchdb session

func (*TokenStore) Create

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

Create create and store the new token information

func (*TokenStore) GetByAccess

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

GetByAccess use the access token for token information data

func (*TokenStore) GetByCode

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

GetByCode use the authorization code for token information data

func (*TokenStore) GetByRefresh

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

GetByRefresh use the refresh token for token information data

func (*TokenStore) RemoveByAccess

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

RemoveByAccess use the access token to delete the token information

func (*TokenStore) RemoveByCode

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

RemoveByCode use the authorization code to delete the token information

func (*TokenStore) RemoveByRefresh

func (ts *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