-
Notifications
You must be signed in to change notification settings - Fork 0
/
get.go
42 lines (37 loc) · 1.04 KB
/
get.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
package servicecognito
import (
"context"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider"
)
type GetUserData struct {
Username string `json:"username"`
}
func GetUser(ctx context.Context, data *GetUserData) (*User, error) {
c, err := getClient(ctx)
if err != nil {
return nil, err
}
out, err := c.AdminGetUser(ctx, &cognitoidentityprovider.AdminGetUserInput{
Username: aws.String(data.Username),
UserPoolId: aws.String(cognitoPool),
})
if err != nil {
return nil, err
}
return &User{
Username: *out.Username,
FirstName: getCognitoUserAttribute(out, cognitoUserAttributeFirstName),
LastName: getCognitoUserAttribute(out, cognitoUserAttributeLastName),
Status: string(out.UserStatus),
Company: getCognitoUserAttribute(out, cognitoUserAttributeCompany),
}, nil
}
func getCognitoUserAttribute(user *cognitoidentityprovider.AdminGetUserOutput, attr string) string {
for _, item := range user.UserAttributes {
if *item.Name == attr {
return *item.Value
}
}
return ""
}