https://github.com/vgarvardt/go-oauth2-pg
PostgreSQL storage for OAuth 2.0
https://github.com/vgarvardt/go-oauth2-pg
Last synced: 2 months ago
JSON representation
PostgreSQL storage for OAuth 2.0
- Host: GitHub
- URL: https://github.com/vgarvardt/go-oauth2-pg
- Owner: vgarvardt
- License: mit
- Created: 2019-02-17T18:06:15.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2025-04-01T12:09:14.000Z (2 months ago)
- Last Synced: 2025-04-09T16:13:53.416Z (2 months ago)
- Language: Go
- Homepage:
- Size: 218 KB
- Stars: 48
- Watchers: 1
- Forks: 11
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PostgreSQL Storage for [OAuth 2.0](https://github.com/go-oauth2/oauth2)
[](https://godoc.org/github.com/vgarvardt/go-oauth2-pg)
[](https://codecov.io/gh/vgarvardt/go-oauth2-pg)
[](https://goreportcard.com/report/github.com/vgarvardt/go-oauth2-pg)
[](http://opensource.org/licenses/MIT)## Install
Storage major version matches [OAuth 2.0](https://github.com/go-oauth2/oauth2) major version,
so use corresponding version (go modules compliant)For `github.com/go-oauth2/oauth2/v4`:
```bash
go get -u github.com/vgarvardt/go-oauth2-pg/v4
```For `gopkg.in/oauth2.v3` see [v3 branch](https://github.com/vgarvardt/go-oauth2-pg/tree/v3).
## 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`](https://github.com/vgarvardt/go-pg-adapter) for easier maintenance.## Usage example
```go
package mainimport (
"context"
"os"
"time""github.com/go-oauth2/oauth2/v4/manage"
"github.com/jackc/pgx/v4"
pg "github.com/vgarvardt/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)
// ...
}
```## Testing
Linter and tests are running for every Pul Request, but it is possible to run linter
and tests locally using `docker` and `make`.Run linter: `make link`. This command runs liner in docker container with the project
source code mounted.Run tests: `make test`. This command runs project dependencies in docker containers
if they are not started yet and runs go tests with coverage.## MIT License
> Copyright (c) 2020 Vladimir Garvardt