-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathforgot_password.go
More file actions
45 lines (37 loc) · 1.47 KB
/
forgot_password.go
File metadata and controls
45 lines (37 loc) · 1.47 KB
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
package authorizer
import (
"encoding/json"
)
// ForgotPasswordRequest defines attributes for forgot_password request
type ForgotPasswordRequest struct {
Email *string `json:"email,omitempty"`
PhoneNumber *string `json:"phone_number,omitempty"`
State *string `json:"state,omitempty"`
RedirectURI *string `json:"redirect_uri,omitempty"`
}
// ForgotPasswordInput is deprecated: Use ForgotPasswordRequest instead
type ForgotPasswordInput = ForgotPasswordRequest
// ForgotPassword is method attached to AuthorizerClient.
// It performs forgot_password mutation on authorizer instance.
// It takes ForgotPasswordRequest reference as parameter and returns ForgotPasswordResponse reference or error.
func (c *AuthorizerClient) ForgotPassword(req *ForgotPasswordRequest) (*ForgotPasswordResponse, error) {
if req.State == nil || StringValue(req.State) == "" {
// generate random state
req.State = NewStringRef(EncodeB64(CreateRandomString()))
}
if req.RedirectURI == nil || StringValue(req.RedirectURI) == "" {
req.RedirectURI = NewStringRef(c.RedirectURL)
}
bytesData, err := c.ExecuteGraphQL(&GraphQLRequest{
Query: `mutation forgotPassword($data: ForgotPasswordRequest!) { forgot_password(params: $data) { message should_show_mobile_otp_screen } }`,
Variables: map[string]interface{}{
"data": req,
},
}, nil)
if err != nil {
return nil, err
}
var res map[string]*ForgotPasswordResponse
json.Unmarshal(bytesData, &res)
return res["forgot_password"], nil
}