-
Notifications
You must be signed in to change notification settings - Fork 0
/
accountCreate.go
53 lines (44 loc) · 1.35 KB
/
accountCreate.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
50
51
52
53
package manage
import (
"context"
"net/http"
"time"
"github.com/fident/go-manage/fidentapi"
"github.com/fident/go-manage/tls"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/metadata"
)
// CreateUserAccount creates a new user account returning identity ID and optionally a temporary session cookie
func (i *Instance) CreateUserAccount(email string, tempSessionCookie bool) (string, *http.Cookie, error) {
meta, err := i.preflightAuth()
if err != nil {
return "", nil, err
}
ctx := metadata.NewOutgoingContext(context.Background(), meta)
conn, err := grpc.Dial(i.fidentEndpoint, grpc.WithTransportCredentials(credentials.NewTLS(tls.FidentTSLConfig)))
if err != nil {
return "", nil, err
}
defer conn.Close()
c := fidentapi.NewAuthClient(conn)
res, err := c.CreateUserAccount(ctx, &fidentapi.CreateUserAccountRequest{
EmailAddress: email,
IssueTemporaryToken: tempSessionCookie,
})
if err != nil {
return "", nil, err
}
var cookie *http.Cookie
if tempSessionCookie {
cookie = &http.Cookie{
Name: res.TemporaryToken.Name,
Value: res.TemporaryToken.Value,
Domain: res.TemporaryToken.Domain,
Expires: time.Unix(res.TemporaryToken.ExpiresEpoch, 0),
Secure: res.TemporaryToken.Secure,
HttpOnly: res.TemporaryToken.HttpOnly,
}
}
return res.IdentityId, cookie, err
}