You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
nucleus/internal/oauth2/client_store.go

36 lines
753 B

package oauth2
import (
"context"
"errors"
"github.com/go-oauth2/oauth2/v4"
"github.com/go-oauth2/oauth2/v4/models"
"gorm.io/gorm"
"nucleus/internal/entities"
)
type ClientStore struct{}
func (c *ClientStore) GetByID(ctx context.Context, id string) (oauth2.ClientInfo, error) {
db, ok := ctx.Value("db").(*gorm.DB)
if !ok {
return nil, errors.New("missing database object")
}
var client entities.Client
err := db.First(&client, "id=?", id).Error
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, errors.New("no client found")
}
return nil, err
}
return &models.Client{
ID: client.AccessKey,
Secret: client.SecretKey,
Domain: client.Domain,
Public: client.Public,
//UserID: "",
}, nil
}