arangoStore

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2023 License: MIT Imports: 7 Imported by: 0

README

go-oauth2-arangodb

GoDoc Go Report Card Maintainability Test Coverage

This package is an ArangoDB storage implementation for go-oauth2 using ArangoDB's official go-driver.

The package is following semantic versioning and is not tied to the versioning of go-oauth2.

Installation

go get github.com/gabor-boros/go-oauth2-arangodb

Example usage

package main

import (
	"context"
	"os"

	arangoDriver "github.com/arangodb/go-driver"
	arangoHTTP "github.com/arangodb/go-driver/http"

	"github.com/go-oauth2/oauth2/v4/manage"

	arangoStore "github.com/gabor-boros/go-oauth2-arangodb"
)

func main() {
	conn, _ := arangoHTTP.NewConnection(arangoHTTP.ConnectionConfig{
		Endpoints: []string{os.Getenv("ARANGO_URL")},
	})

	client, _ := arangoDriver.NewClient(arangoDriver.ClientConfig{
		Connection:     conn,
		Authentication: arangoDriver.BasicAuthentication(os.Getenv("ARANGO_USER"), os.Getenv("ARANGO_PASSWORD")),
	})

	db, _ := client.Database(context.Background(), os.Getenv("ARANGO_DB"))
	
	clientStore, _ := arangoStore.NewClientStore(
		arangoStore.WithClientStoreDatabase(db),
		arangoStore.WithClientStoreCollection("oauth2_clients"),
	)

	tokenStore, _ := arangoStore.NewTokenStore(
		arangoStore.WithTokenStoreDatabase(db),
		arangoStore.WithTokenStoreCollection("oauth2_tokens"),
	)

	manager := manage.NewDefaultManager()
	manager.MapTokenStorage(tokenStore)
	manager.MapClientStorage(clientStore)
	
	// ...
}

Contributing

Contributions are welcome! Please open an issue or a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Index

Constants

View Source
const (
	// DefaultClientStoreCollection is the default collection for storing clients.
	DefaultClientStoreCollection = "oauth2_clients"
)
View Source
const (
	// DefaultTokenStoreCollection is the default collection for storing tokens.
	DefaultTokenStoreCollection = "oauth2_tokens" // nolint: gosec
)

Variables

View Source
var (
	// ErrNoCollection is returned when no collection is provided.
	ErrNoCollection = fmt.Errorf("no collection provided")
	// ErrNoDatabase is returned when no database is provided.
	ErrNoDatabase = fmt.Errorf("no database provided")
)

Functions

This section is empty.

Types

type ClientStore

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

ClientStore is a data struct that stores oauth2 client information.

func NewClientStore

func NewClientStore(opts ...ClientStoreOption) (*ClientStore, error)

NewClientStore creates a new ClientStore.

func (*ClientStore) Create

func (s *ClientStore) Create(info oauth2.ClientInfo) error

Create creates a new client in the store.

func (*ClientStore) GetByID

func (s *ClientStore) GetByID(ctx context.Context, key string) (oauth2.ClientInfo, error)

GetByID returns the client information by key from the store.

type ClientStoreItem

type ClientStoreItem struct {
	Key    string `json:"_key"`
	Secret string `json:"secret"`
	Domain string `json:"domain"`
	Data   []byte `json:"data"`
}

ClientStoreItem data item

type ClientStoreOption

type ClientStoreOption func(*ClientStore) error

ClientStoreOption is a function that configures the ClientStore.

func WithClientStoreCollection

func WithClientStoreCollection(collection string) ClientStoreOption

WithClientStoreCollection configures the collection for the ClientStore.

func WithClientStoreDatabase

func WithClientStoreDatabase(db arangoDriver.Database) ClientStoreOption

WithClientStoreDatabase configures the database for the ClientStore.

type TokenStore

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

TokenStore is a data struct that stores oauth2 client information.

func NewTokenStore

func NewTokenStore(opts ...TokenStoreOption) (*TokenStore, error)

NewTokenStore creates a new TokenStore.

func (*TokenStore) Create

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

Create creates a new token in the store.

func (*TokenStore) GetByAccess

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

GetByAccess returns the token by its access token.

func (*TokenStore) GetByCode

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

GetByCode returns the token by its authorization code.

func (*TokenStore) GetByRefresh

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

GetByRefresh returns the token by its refresh token.

func (*TokenStore) RemoveByAccess

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

func (*TokenStore) RemoveByCode

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

RemoveByCode deletes the token by its authorization code.

func (*TokenStore) RemoveByRefresh

func (s *TokenStore) RemoveByRefresh(ctx context.Context, refresh string) error

type TokenStoreItem

type TokenStoreItem struct {
	Key       string    `json:"_key,omitempty"`
	Code      string    `json:"code"`
	Access    string    `json:"access_token"`
	Refresh   string    `json:"refresh_token"`
	Data      []byte    `json:"data"`
	CreatedAt time.Time `json:"created_at"`
	ExpiresAt time.Time `json:"expires_at"`
}

TokenStoreItem data item

type TokenStoreOption

type TokenStoreOption func(*TokenStore) error

TokenStoreOption is a function that configures the TokenStore.

func WithTokenStoreCollection

func WithTokenStoreCollection(collection string) TokenStoreOption

WithTokenStoreCollection configures the collection for the TokenStore.

func WithTokenStoreDatabase

func WithTokenStoreDatabase(db arangoDriver.Database) TokenStoreOption

WithTokenStoreDatabase configures the database for the TokenStore.

Jump to

Keyboard shortcuts

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