Categorygithub.com/gabor-boros/go-oauth2-pg
modulepackage
0.0.0-20230608073400-a93883d73d34
Repository: https://github.com/gabor-boros/go-oauth2-pg.git
Documentation: pkg.go.dev

# README

go-oauth2-pg

GoDoc Go Report Card Maintainability Test Coverage

This package is a Postgres storage implementation for go-oauth2 using pgx.

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-pg

Example usage

package main

import (
	"context"
	"os"

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

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

	pgstore "github.com/gabor-boros/go-oauth2-pg"
)

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, _ := pgstore.NewClientStore(
		pgstore.WithClientStoreDatabase(db),
		pgstore.WithClientStoreTable("oauth2_clients"),
	)

	tokenStore, _ := pgstore.NewTokenStore(
		pgstore.WithTokenStoreDatabase(db),
		pgstore.WithTokenStoreTable("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.

# Functions

NewClientStore creates a new ClientStore.
NewTokenStore creates a new TokenStore.
WithClientStoreConnPool configures the connection pool.
WithClientStoreLogger configures the logger.
WithClientStoreTable configures the auth token table.
WithTokenStoreCleanupInterval configures the cleanup interval.
WithTokenStoreConnPool configures the connection pool.
WithTokenStoreLogger configures the logger.
WithTokenStoreTable configures the auth token table.

# Constants

DefaultClientStoreTable is the default collection for storing clients.
nolint: gosec.
debug level.
error level.
info level.
warn level.

# Variables

ErrNoConnPool is returned when no database was provided.
ErrNoLogger is returned when no logger was provided.
ErrNoTable is returned when no table was provided.

# Structs

ClientStore is a data struct that stores oauth2 client information.
ClientStoreItem data item.
NoopLogger is a logger that does nothing.
TokenStore is a data struct that stores oauth2 token information.
TokenStoreItem data item.

# Interfaces

Logger wraps a logger to log messages.

# Type aliases

ClientStoreOption is a function that configures the ClientStore.
LogLevel is a log level.
TokenStoreOption is a function that configures the TokenStore.