Skip to content

this is my implementation ofhttps://github.com/vgarvardt/go-pg-adapter

License

Notifications You must be signed in to change notification settings

brutalzinn/go-oauth2-pg

Repository files navigation

PostgreSQL Storage for OAuth 2.0

GoDoc Coverage Status ReportCard License

Install

Storage major version matches OAuth 2.0 major version, so use corresponding version (go modules compliant)

For github.com/go-oauth2/oauth2/v4:

go get -u github.com/brutalzinn/go-oauth2-pg/v4

For gopkg.in/oauth2.v3 see v3 branch.

PostgreSQL drivers

The store accepts an adapter interface that interacts with the DB. Adapter and implementations extracted to separate package github.com/vgarvardt/go-pg-adapter for easier maintenance.

Usage example

package main

import (
  "context"
  "os"
  "time"

  "github.com/go-oauth2/oauth2/v4/manage"
  "github.com/jackc/pgx/v4"
  pg "github.com/brutalzinn/go-oauth2-pg/v4
"
  "github.com/vgarvardt/go-pg-adapter/pgx4adapter"
)

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)
  // ...
}

MIT License

Copyright (c) 2020 Vladimir Garvardt

About

this is my implementation ofhttps://github.com/vgarvardt/go-pg-adapter

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •