-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsignup.go
47 lines (42 loc) · 2.07 KB
/
signup.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
package authorizer
import (
"encoding/json"
"fmt"
)
// SignUpInput defines attributes for signup request
type SignUpInput struct {
Email *string `json:"email,omitempty"`
Password string `json:"password"`
ConfirmPassword string `json:"confirm_password"`
GivenName *string `json:"given_name,omitempty"`
FamilyName *string `json:"family_name,omitempty"`
MiddleName *string `json:"middle_name,omitempty"`
NickName *string `json:"nick_name,omitempty"`
Picture *string `json:"picture,omitempty"`
Gender *string `json:"gender,omitempty"`
BirthDate *string `json:"birthdate,omitempty"`
PhoneNumber *string `json:"phone_number,omitempty"`
Roles []*string `json:"roles,omitempty"`
Scope []*string `json:"scope,omitempty"`
RedirectURI *string `json:"redirect_uri,omitempty"`
IsMultiFactorAuthEnabled *bool `json:"is_multi_factor_auth_enabled,omitempty"`
AppData map[string]interface{} `json:"app_data,omitempty"`
}
// SignUp is method attached to AuthorizerClient.
// It performs signup mutation on authorizer instance.
// It takes SignUpInput reference as parameter and returns AuthTokenResponse reference or error.
// For implementation details check SignUpExample examples/signup.go
func (c *AuthorizerClient) SignUp(req *SignUpInput) (*AuthTokenResponse, error) {
bytesData, err := c.ExecuteGraphQL(&GraphQLRequest{
Query: fmt.Sprintf(`mutation signup($data: SignUpInput!) { signup(params: $data) { %s }}`, AuthTokenResponseFragment),
Variables: map[string]interface{}{
"data": req,
},
}, nil)
if err != nil {
return nil, err
}
var res map[string]*AuthTokenResponse
json.Unmarshal(bytesData, &res)
return res["signup"], nil
}