modulepackage
1.3.0
Repository: https://github.com/vgarvardt/go-oauth2-pg.git
Documentation: pkg.go.dev
# README
PostgreSQL Storage for OAuth 2.0
Install
$ go get -u -v github.com/vgarvardt/go-oauth2-pg
PostgreSQL drivers
The store accepts an adapter interface that interacts with the DB. Adapter and implementations are extracted to separate package github.com/vgarvardt/go-pg-adapter
for easier maintenance.
Usage example
package main
import (
"context"
"os"
"time"
"github.com/jackc/pgx/v4"
pg "github.com/vgarvardt/go-oauth2-pg"
"github.com/vgarvardt/go-pg-adapter/pgx4adapter"
"gopkg.in/oauth2.v3/manage"
)
func main() {
pgxConn, _ := pgx.Connect(context.TODO(), os.Getenv("DB_URI"))
manager := manage.NewDefaultManager()
// use PostgreSQL token store with pgx.Connection adapter
adapter := pgx4adapter.NewConn(pgxConn)
tokenStore, _ := pg.NewTokenStore(adapter, pg.WithTokenStoreGCInterval(time.Minute))
defer tokenStore.Close()
clientStore, _ := pg.NewClientStore(adapter)
manager.MapTokenStorage(tokenStore)
manager.MapClientStorage(clientStore)
// ...
}
How to run tests
You will need running PostgreSQL instance. E.g. the one running in docker and exposing a port to a host system
docker run --rm -p 5432:5432 -it -e POSTGRES_PASSWORD=oauth2 -e POSTGRES_USER=oauth2 -e POSTGRES_DB=oauth2 postgres:10
Now you can run tests using the running PostgreSQL instance using PG_URI
environment variable
PG_URI=postgres://oauth2:oauth2@localhost:5432/oauth2?sslmode=disable go test -cover ./...
MIT License
Copyright (c) 2019 Vladimir Garvardt
# Functions
NewClientStore creates PostgreSQL store instance.
NewTokenStore creates PostgreSQL store instance.
WithClientStoreInitTableDisabled returns option that disables table creation on client store instantiation.
WithClientStoreLogger returns option that sets client store logger implementation.
WithClientStoreTableName returns option that sets client store table name.
WithTokenStoreGCDisabled returns option that disables token store garbage collection.
WithTokenStoreGCInterval returns option that sets token store garbage collection interval.
WithTokenStoreInitTableDisabled returns option that disables table creation on token store instantiation.
WithTokenStoreLogger returns option that sets token store logger implementation.
WithTokenStoreTableName returns option that sets token store table name.
# Structs
ClientStore PostgreSQL client store.
ClientStoreItem data item.
TokenStore PostgreSQL token store.
TokenStoreItem data item.
# Interfaces
Logger is the PostgreSQL store logger interface.
# Type aliases
ClientStoreOption is the configuration options type for client store.
TokenStoreOption is the configuration options type for token store.