54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package initialization
|
|
|
|
import (
|
|
"fmt"
|
|
gs "gitee.ltd/go-oauth2/gin-server"
|
|
"github.com/go-oauth2/oauth2/v4/manage"
|
|
"github.com/go-oauth2/oauth2/v4/server"
|
|
rds "github.com/go-oauth2/redis/v4"
|
|
"github.com/go-redis/redis/v8"
|
|
"goweb/config"
|
|
)
|
|
|
|
func CreateOAuth2Server() {
|
|
manager := manage.NewDefaultManager()
|
|
|
|
// use mysql token store
|
|
store := rds.NewRedisStore(&redis.Options{
|
|
Addr: fmt.Sprintf("%s:%s", config.RedisConfig.Host, config.RedisConfig.Port),
|
|
Password: config.RedisConfig.Password,
|
|
DB: config.RedisConfig.Db,
|
|
}, "oauth2:token:")
|
|
|
|
// token store
|
|
manager.MapTokenStorage(store)
|
|
|
|
// client store
|
|
//clientStore := store.NewClientStore()
|
|
//clientStore.Set("000000", &models.Client{
|
|
// ID: "000000",
|
|
// Secret: "999999",
|
|
// Domain: "http://localhost",
|
|
//})
|
|
//manager.MapClientStorage(clientStore)
|
|
//ctx := context.Background()
|
|
//info := &models.Token{
|
|
// ClientID: "1",
|
|
// UserID: "1_1",
|
|
// RedirectURI: "http://localhost/",
|
|
// Scope: "all",
|
|
// Code: "11_11_11",
|
|
// CodeCreateAt: time.Now(),
|
|
// CodeExpiresIn: time.Second * 5,
|
|
//}
|
|
//err := store.Create(ctx, info)
|
|
//if err != nil {
|
|
// global.Log.Panic(err.Error())
|
|
//}
|
|
|
|
// Initialize the oauth2 service
|
|
gs.InitServer(manager)
|
|
gs.SetAllowGetAccessRequest(true)
|
|
gs.SetClientInfoHandler(server.ClientFormHandler)
|
|
}
|