-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.go
57 lines (48 loc) · 2.07 KB
/
auth.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
48
49
50
51
52
53
54
55
56
57
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package farquest
import (
"context"
"fmt"
"net/http"
"github.com/FarquestSocial/farquest-go/internal/apijson"
"github.com/FarquestSocial/farquest-go/internal/param"
"github.com/FarquestSocial/farquest-go/internal/requestconfig"
"github.com/FarquestSocial/farquest-go/option"
)
// AuthService contains methods and other services that help with interacting with
// the farquest API. Note, unlike clients, this service does not read variables
// from the environment automatically. You should not instantiate this service
// directly, and instead use the [NewAuthService] method instead.
type AuthService struct {
Options []option.RequestOption
}
// NewAuthService generates a new service that applies the given options to each
// request. These options are applied after the parent client's options (if there
// is one), and before any request-specific options.
func NewAuthService(opts ...option.RequestOption) (r *AuthService) {
r = &AuthService{}
r.Options = opts
return
}
// Callback to session with Privy Auth, returns URL to redirect back to your app
func (r *AuthService) Callback(ctx context.Context, body AuthCallbackParams, opts ...option.RequestOption) (err error) {
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithHeader("Accept", "")}, opts...)
path := "auth/callback"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, nil, opts...)
return
}
// Get the redirect URL to start a session
func (r *AuthService) GetState(ctx context.Context, state string, opts ...option.RequestOption) (err error) {
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithHeader("Accept", "")}, opts...)
path := fmt.Sprintf("auth/%s", state)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, nil, opts...)
return
}
type AuthCallbackParams struct {
State param.Field[string] `json:"state,required"`
}
func (r AuthCallbackParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}