Skip to content

imrenagi/go-oauth2-mysql

Repository files navigation

MySQL Storage for OAuth 2.0

Build Codecov GoDoc License

Install

$ go get -u -v github.com/imrenagi/go-oauth2-mysql

MySQL drivers

The store accepts an sqlx.DB which interacts with the DB. sqlx.DB is a specific implementations from github.com/jmoiron/sqlx

Usage example

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

How to run tests

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 .

MIT License

Copyright (c) 2019 Imre Nagi

Credits

About

MYSQL Oauth store implementation for https://gopkg.in/oauth2.v3

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages