mongo

package module
v0.0.0-...-2987f45 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2020 License: MIT Imports: 9 Imported by: 0

README

Mongo Storage for OAuth 2.0

Build Codecov ReportCard GoDoc License

Install

$ go get -u -v gopkg.in/go-oauth2/mongo.v3

Usage

package main

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

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

	// use mongodb token store
	manager.MapTokenStorage(
		mongo.NewTokenStore(mongo.NewConfig(
			"mongodb://127.0.0.1:27017",
			"oauth2",
		)),
	)
	// ...
}

MIT License

Copyright (c) 2016 Lyric

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	URL string
	DB  string
}

Config mongodb configuration parameters

func NewConfig

func NewConfig(url, db string) *Config

NewConfig create mongodb configuration

type TokenConfig

type TokenConfig struct {
	// store txn collection name(The default is oauth2)
	TxnCName string
	// store token based data collection name(The default is oauth2_basic)
	BasicCName string
	// store access token data collection name(The default is oauth2_access)
	AccessCName string
	// store refresh token data collection name(The default is oauth2_refresh)
	RefreshCName 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 MongoDB 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 mongo.Session, 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 mongo session

func (*TokenStore) Create

func (ts *TokenStore) Create(ctx context.Context, info oauth2.TokenInfo) (err error)

Create create and store the new token information

func (*TokenStore) GetByAccess

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

GetByAccess use the access token for token information data

func (*TokenStore) GetByCode

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

GetByCode use the authorization code for token information data

func (*TokenStore) GetByRefresh

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

GetByRefresh use the refresh token for token information data

func (*TokenStore) RemoveByAccess

func (ts *TokenStore) RemoveByAccess(ctx context.Context, access string) (err error)

RemoveByAccess use the access token to delete the token information

func (*TokenStore) RemoveByCode

func (ts *TokenStore) RemoveByCode(ctx context.Context, code string) (err error)

RemoveByCode use the authorization code to delete the token information

func (*TokenStore) RemoveById

func (ts *TokenStore) RemoveById(ctx context.Context, dbName string, id string) (err error)

RemoveBy use dbname and bson document filter to delete

func (*TokenStore) RemoveByRefresh

func (ts *TokenStore) RemoveByRefresh(ctx context.Context, 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