-
Notifications
You must be signed in to change notification settings - Fork 1
/
static_matcher.go
49 lines (41 loc) · 1.17 KB
/
static_matcher.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
39
40
41
42
43
44
45
46
47
48
49
package auth
import (
"context"
"fmt"
"strings"
"github.com/davecgh/go-spew/spew"
"github.com/markbates/goth"
"github.com/minskylab/collecta/ent/domain"
"github.com/pkg/errors"
)
func (collectaAuth *Auth) matchGoogleUserWithCollectaDomain(ctx context.Context, rawUser goth.User) (string, error) {
spew.Dump(rawUser)
domainHost, ok := rawUser.RawData["hd"].(string)
fmt.Println("domainHost, ok: ", domainHost, ok)
if !ok {
fmt.Println("email: " + rawUser.Email)
parts := strings.Split(rawUser.Email, "@")
fmt.Println("parts: ", parts)
if len(parts) != 2 {
return "", errors.New("invalid domain in raw rawUser data")
}
domainHost = strings.TrimSpace(parts[1])
}
fmt.Println("domainHost: "+domainHost)
domainExists, err := collectaAuth.db.Ent.Domain.Query().
Where(domain.Domain(domainHost)).
Exist(ctx)
if err != nil {
return "", errors.Wrap(err, "error at fetch domain")
}
if !domainExists {
return "", errors.New("domain of rawUser not exist")
}
dom, err := collectaAuth.db.Ent.Domain.Query().
Where(domain.Domain(domainHost)).
Only(ctx)
if err != nil {
return "", errors.Wrap(err, "error at fetch domain")
}
return dom.Callback, nil
}