-
Notifications
You must be signed in to change notification settings - Fork 12
/
personalIntegration.service.go
38 lines (31 loc) · 1.26 KB
/
personalIntegration.service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package service
import (
"fmt"
"github.com/openline-ai/openline-customer-os/packages/server/customer-os-common-module/utils"
postgresEntity "github.com/openline-ai/openline-customer-os/packages/server/customer-os-postgres-repository/entity"
postgresRepository "github.com/openline-ai/openline-customer-os/packages/server/customer-os-postgres-repository/repository"
)
type Integration string
const (
CALCOM Integration = "calcom"
)
const CalComHeader = "x-cal-signature-256"
func SignatureCheck(hSignature string, body []byte, personalIntegrationRepository postgresRepository.PersonalIntegrationRepository, tenant, email, integration string) error {
if hSignature != "" {
result := personalIntegrationRepository.FindIntegration(tenant, email, integration)
if result.Error != nil {
return fmt.Errorf("SignatureCheck error: %v", result.Error.Error())
}
secret := result.Result.(*postgresEntity.PersonalIntegration)
if secret == nil {
return fmt.Errorf("SignatureCheck error: no information found")
}
cSignature := utils.Hmac(body, []byte(secret.Secret))
if hSignature != *cSignature {
return fmt.Errorf("SignatureCheck error: signature mismatch")
}
return nil
} else {
return fmt.Errorf("SignatureCheck error: signature header not found")
}
}