mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Separate authn flow from analytics (#68327)
* separate authn flow from analytics * lint fix
This commit is contained in:
@@ -397,14 +397,11 @@ func (ss *sqlStore) GetSignedInUser(ctx context.Context, query *user.GetSignedIn
|
||||
u.help_flags1 as help_flags1,
|
||||
u.last_seen_at as last_seen_at,
|
||||
(SELECT COUNT(*) FROM org_user where org_user.user_id = u.id) as org_count,
|
||||
user_auth.auth_module as external_auth_module,
|
||||
user_auth.auth_id as external_auth_id,
|
||||
org.name as org_name,
|
||||
org_user.role as org_role,
|
||||
org.id as org_id,
|
||||
u.is_service_account as is_service_account
|
||||
FROM ` + ss.dialect.Quote("user") + ` as u
|
||||
LEFT OUTER JOIN user_auth on user_auth.user_id = u.id
|
||||
LEFT OUTER JOIN org_user on org_user.org_id = ` + orgId + ` and org_user.user_id = u.id
|
||||
LEFT OUTER JOIN org on org.id = org_user.org_id `
|
||||
|
||||
@@ -438,11 +435,6 @@ func (ss *sqlStore) GetSignedInUser(ctx context.Context, query *user.GetSignedIn
|
||||
signedInUser.OrgName = "Org missing"
|
||||
}
|
||||
|
||||
if signedInUser.ExternalAuthModule != "oauth_grafana_com" {
|
||||
signedInUser.ExternalAuthID = ""
|
||||
}
|
||||
|
||||
signedInUser.Analytics = buildUserAnalyticsSettings(signedInUser, ss.cfg.IntercomSecret)
|
||||
return nil
|
||||
})
|
||||
return &signedInUser, err
|
||||
|
||||
@@ -2,9 +2,6 @@ package userimpl
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/hmac"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
@@ -466,25 +463,3 @@ func (s *Service) supportBundleCollector() supportbundles.Collector {
|
||||
Fn: collectorFn,
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user