Chore: Pass signed user_hash to Intercom via Rudderstack (#63921) (#64145)

* move analytics identifiers to backend

* implement hash function

* grab secret from env

* expose and retrieve intercom secret from config

* concat email with appUrl to ensure uniqueness

* revert to just using email

* Revert "revert to just using email"

This reverts commit 8f10f9b1bc.

* add docstring

(cherry picked from commit d61bcdf4ca)
This commit is contained in:
Ashley Harrison
2023-03-03 10:06:13 -05:00
committed by GitHub
parent 1548edc40e
commit 4ee064da11
15 changed files with 90 additions and 66 deletions
+25
View File
@@ -2,6 +2,9 @@ package userimpl
import (
"context"
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
"errors"
"fmt"
"strings"
@@ -547,3 +550,25 @@ func (s *Service) CreateServiceAccount(ctx context.Context, cmd *user.CreateUser
}
return usr, nil
}
func hashUserIdentifier(identifier string, secret string) string {
key := []byte(secret)
h := hmac.New(sha256.New, key)
h.Write([]byte(identifier))
return hex.EncodeToString(h.Sum(nil))
}
func buildUserAnalyticsSettings(signedInUser user.SignedInUser, intercomSecret string) user.AnalyticsSettings {
var settings user.AnalyticsSettings
if signedInUser.ExternalAuthID != "" {
settings.Identifier = signedInUser.ExternalAuthID
} else {
settings.Identifier = signedInUser.Email + "@" + setting.AppUrl
}
if intercomSecret != "" {
settings.IntercomIdentifier = hashUserIdentifier(settings.Identifier, intercomSecret)
}
return settings
}