-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoauth.go
41 lines (33 loc) · 1.04 KB
/
oauth.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
package otplessgo
import "fmt"
// Represents an oAuth initialization payload
type OAuthPayload struct {
Channel OAuthChannel `json:"channel"`
RedirectURI string `json:"redirect_uri"`
}
// OAuth initialization success response
type OAuthResponse struct {
RequestId string `json:"requestId"`
Link string `json:"link"`
}
// Sends a initialization request for the oAuth Channel.
func (o *OTPLessClient) InitiateOAuth(payload *OAuthPayload) (*ApiResponse[OAuthResponse], error) {
var failureResp ApiErrorResponse
var successResp OAuthResponse
resp, err := o.restyClient.R().SetBody(payload).SetError(&failureResp).SetResult(&successResp).Post("/initiate/oauth")
if err != nil {
return nil, err
}
if resp.StatusCode() > 300 {
return &ApiResponse[OAuthResponse]{
Response: nil,
ErrorResponse: &failureResp,
RawResponse: resp.RawResponse,
}, fmt.Errorf(failureResp.Message)
}
return &ApiResponse[OAuthResponse]{
Response: &successResp,
ErrorResponse: &failureResp,
RawResponse: resp.RawResponse,
}, nil
}