Categorygithub.com/iodeal/go-oauth2-database-store/v4
modulepackage
4.0.5
Repository: https://github.com/iodeal/go-oauth2-database-store.git
Documentation: pkg.go.dev

# README

Database storage for OAuth 2.0

Inherited from MySQL storage for OAuth 2.0

License

Install

$ go get -v github.com/iodeal/go-oauth2-database-store/v4

Usage

package main

import (
	"context"
	"fmt"
	"time"

	dbstore "github.com/iodeal/go-oauth2-database-store/v4"

	"github.com/go-oauth2/oauth2/v4/models"

	"github.com/go-oauth2/oauth2/v4/manage"

	_ "github.com/lib/pq"
)

func main() {
	manager := manage.NewDefaultManager()

	// use mysql token store
	store := dbstore.NewDefaultStore(
		dbstore.NewConfig("postgres", "host=localhost port=5432 user=postgres password=123456 dbname=postgres sslmode=disable"),
	)

	defer store.Close()

	manager.MapTokenStorage(store)
	info := &models.Token{
		ClientID:      "123",
		UserID:        "adb",
		RedirectURI:   "http://localhost/",
		Scope:         "all",
		Code:          "12_34_56",
		CodeCreateAt:  time.Now(),
		CodeExpiresIn: time.Second * 5,
	}
	err := store.Create(context.TODO(), info)
	if err != nil {
		log.Fatal("create store err:", err)
	} else {
		fmt.Println("create ok!")
	}
}

MIT License

Copyright (c) 2018 Lyric
Copyright (c) 2022 iodeal

# Functions

NewConfig create database configuration instance.
NewDefaultStore create database store instance.
NewStore create database store instance, config database configuration, tableName table name (default oauth2_token), GC time interval (in seconds, default 600).
NewStoreWithDB create database store instance, db sql.DB, tableName table name (default oauth2_token), GC time interval (in seconds, default 600).
NewStoreWithOpts create database store instance with apply custom input, db sql.DB, tableName table name (default oauth2_token), GC time interval (in seconds, default 600).
WithGCTimeInterval sets the time interval for garbage collection.
WithTableName sets the table name for the store.

# Structs

Config database configuration.
Store database token store.
StoreItem data item.

# Interfaces

No description provided by the author