1
0
forked from baron/baron-sso

consent 2차 검증 추가

This commit is contained in:
2026-04-24 14:21:57 +09:00
parent 9072bbc42d
commit 26180ae5d1
2 changed files with 58 additions and 5 deletions

View File

@@ -3,6 +3,7 @@ package repository
import (
"baron-sso-backend/internal/domain"
"context"
"errors"
"gorm.io/gorm"
)
@@ -13,6 +14,7 @@ type ClientConsentRepository interface {
List(ctx context.Context, clientID string, limit, offset int) ([]domain.ClientConsentWithTenantInfo, int64, error)
ListByTenant(ctx context.Context, clientID, tenantID string, limit, offset int) ([]domain.ClientConsentWithTenantInfo, int64, error)
ListBySubject(ctx context.Context, subject string) ([]domain.ClientConsent, error)
Find(ctx context.Context, clientID, subject string) (*domain.ClientConsent, error)
}
type clientConsentRepo struct {
@@ -23,6 +25,20 @@ func NewClientConsentRepository(db *gorm.DB) ClientConsentRepository {
return &clientConsentRepo{db: db}
}
func (r *clientConsentRepo) Find(ctx context.Context, clientID, subject string) (*domain.ClientConsent, error) {
var consent domain.ClientConsent
err := r.db.WithContext(ctx).Unscoped().
Where("client_id = ? AND subject = ?", clientID, subject).
First(&consent).Error
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, nil
}
return nil, err
}
return &consent, nil
}
func (r *clientConsentRepo) Upsert(ctx context.Context, consent *domain.ClientConsent) error {
return r.db.WithContext(ctx).Unscoped().
Where("client_id = ? AND subject = ?", consent.ClientID, consent.Subject).