-
Notifications
You must be signed in to change notification settings - Fork 1
/
verify_otp.go
34 lines (29 loc) · 987 Bytes
/
verify_otp.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
package authorizer
import (
"encoding/json"
"fmt"
)
// VerifyOTPInput defines attributes for verify_otp request
type VerifyOTPInput struct {
Email *string `json:"email"`
OTP string `json:"otp"`
PhoneNumber *string `json:"phone_number"`
}
// VerifyOTP is method attached to AuthorizerClient.
// It performs verify_otp mutation on authorizer instance.
// It returns AuthTokenResponse reference or error.
// For implementation details check VerifyOTPExample examples/verify_otp.go
func (c *AuthorizerClient) VerifyOTP(req *VerifyOTPInput) (*AuthTokenResponse, error) {
bytesData, err := c.ExecuteGraphQL(&GraphQLRequest{
Query: fmt.Sprintf(`mutation verifyOtp($data: VerifyOTPRequest!) { verify_otp(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["verify_otp"], nil
}