-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathverify_otp.go
More file actions
38 lines (32 loc) · 1.09 KB
/
verify_otp.go
File metadata and controls
38 lines (32 loc) · 1.09 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
package authorizer
import (
"encoding/json"
"fmt"
)
// VerifyOTPRequest defines attributes for verify_otp request
type VerifyOTPRequest struct {
Email *string `json:"email"`
OTP string `json:"otp"`
PhoneNumber *string `json:"phone_number"`
IsTotp *bool `json:"is_totp,omitempty"`
State *string `json:"state,omitempty"`
}
// VerifyOTPInput is deprecated: Use VerifyOTPRequest instead
type VerifyOTPInput = VerifyOTPRequest
// VerifyOTP is method attached to AuthorizerClient.
// It performs verify_otp mutation on authorizer instance.
// It returns AuthTokenResponse reference or error.
func (c *AuthorizerClient) VerifyOTP(req *VerifyOTPRequest) (*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
}