MySQL Storage for OAuth 2.0
$ go get -u -v github.com/imrenagi/go-oauth2-mysql
The store accepts an sqlx.DB
which interacts with the DB. sqlx.DB
is a specific implementations from github.com/jmoiron/sqlx
package main
import (
_ "github.com/go-sql-driver/mysql"
mysql "github.com/imrenagi/go-oauth2-mysql"
"github.com/jmoiron/sqlx"
)
func main() {
db, err := sqlx.Connect("mysql", "user:password@tcp(127.0.0.1:3306)/oauth_db?parseTime=true")
if err != nil {
log.Fatalln(err)
}
clientStore, _ := mysql.NewClientStore(db, mysql.WithClientStoreTableName("custom_table_name"))
tokenStore, _ := mysql.NewTokenStore(db)
}
You will need running MySQL instance. E.g. the one running in docker and exposing a port to a host system
$ docker run -it -p 3306:3306 -e MYSQL_ROOT_PASSWORD=oauth2 -d mysql
$ docker exec -it <container_id> bash
$ mysql -u root -poauth2
> create database oauth_db
$ MYSQL_URI=root:oauth2@tcp(127.0.0.1:3306)/oauth_db?parseTime=true go test .
Copyright (c) 2019 Imre Nagi
- Oauth Postgres Implementation
github.com/vgarvardt/go-pg-adapter