-
Notifications
You must be signed in to change notification settings - Fork 0
/
oauth2register.go
executable file
·212 lines (177 loc) · 8.92 KB
/
oauth2register.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package polar
import (
"context"
"errors"
"fmt"
"net/http"
"github.com/polarsource/polar-go/internal/apijson"
"github.com/polarsource/polar-go/internal/param"
"github.com/polarsource/polar-go/internal/requestconfig"
"github.com/polarsource/polar-go/option"
)
// Oauth2RegisterService contains methods and other services that help with
// interacting with the polar 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 [NewOauth2RegisterService] method instead.
type Oauth2RegisterService struct {
Options []option.RequestOption
}
// NewOauth2RegisterService 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 NewOauth2RegisterService(opts ...option.RequestOption) (r *Oauth2RegisterService) {
r = &Oauth2RegisterService{}
r.Options = opts
return
}
// Create an OAuth2 client.
func (r *Oauth2RegisterService) New(ctx context.Context, body Oauth2RegisterNewParams, opts ...option.RequestOption) (res *Oauth2RegisterNewResponse, err error) {
opts = append(r.Options[:], opts...)
path := "v1/oauth2/register"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Get an OAuth2 client by Client ID.
func (r *Oauth2RegisterService) Get(ctx context.Context, clientID string, opts ...option.RequestOption) (res *Oauth2RegisterGetResponse, err error) {
opts = append(r.Options[:], opts...)
if clientID == "" {
err = errors.New("missing required client_id parameter")
return
}
path := fmt.Sprintf("v1/oauth2/register/%s", clientID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// Update an OAuth2 client.
func (r *Oauth2RegisterService) Update(ctx context.Context, params Oauth2RegisterUpdateParams, opts ...option.RequestOption) (res *Oauth2RegisterUpdateResponse, err error) {
opts = append(r.Options[:], opts...)
if params.PathClientID.Value == "" {
err = errors.New("missing required path_client_id parameter")
return
}
path := fmt.Sprintf("v1/oauth2/register/%s", params.PathClientID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPut, path, params, &res, opts...)
return
}
// Delete an OAuth2 client.
func (r *Oauth2RegisterService) Delete(ctx context.Context, clientID string, opts ...option.RequestOption) (res *Oauth2RegisterDeleteResponse, err error) {
opts = append(r.Options[:], opts...)
if clientID == "" {
err = errors.New("missing required client_id parameter")
return
}
path := fmt.Sprintf("v1/oauth2/register/%s", clientID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
return
}
type Oauth2RegisterNewResponse = interface{}
type Oauth2RegisterGetResponse = interface{}
type Oauth2RegisterUpdateResponse = interface{}
type Oauth2RegisterDeleteResponse = interface{}
type Oauth2RegisterNewParams struct {
ClientName param.Field[string] `json:"client_name,required"`
RedirectUris param.Field[[]string] `json:"redirect_uris,required" format:"uri"`
ClientUri param.Field[string] `json:"client_uri"`
GrantTypes param.Field[[]Oauth2RegisterNewParamsGrantType] `json:"grant_types"`
LogoUri param.Field[string] `json:"logo_uri" format:"uri"`
PolicyUri param.Field[string] `json:"policy_uri" format:"uri"`
ResponseTypes param.Field[[]Oauth2RegisterNewParamsResponseType] `json:"response_types"`
Scope param.Field[string] `json:"scope"`
TokenEndpointAuthMethod param.Field[Oauth2RegisterNewParamsTokenEndpointAuthMethod] `json:"token_endpoint_auth_method"`
TosUri param.Field[string] `json:"tos_uri" format:"uri"`
}
func (r Oauth2RegisterNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type Oauth2RegisterNewParamsGrantType string
const (
Oauth2RegisterNewParamsGrantTypeAuthorizationCode Oauth2RegisterNewParamsGrantType = "authorization_code"
Oauth2RegisterNewParamsGrantTypeRefreshToken Oauth2RegisterNewParamsGrantType = "refresh_token"
)
func (r Oauth2RegisterNewParamsGrantType) IsKnown() bool {
switch r {
case Oauth2RegisterNewParamsGrantTypeAuthorizationCode, Oauth2RegisterNewParamsGrantTypeRefreshToken:
return true
}
return false
}
type Oauth2RegisterNewParamsResponseType string
const (
Oauth2RegisterNewParamsResponseTypeCode Oauth2RegisterNewParamsResponseType = "code"
)
func (r Oauth2RegisterNewParamsResponseType) IsKnown() bool {
switch r {
case Oauth2RegisterNewParamsResponseTypeCode:
return true
}
return false
}
type Oauth2RegisterNewParamsTokenEndpointAuthMethod string
const (
Oauth2RegisterNewParamsTokenEndpointAuthMethodClientSecretBasic Oauth2RegisterNewParamsTokenEndpointAuthMethod = "client_secret_basic"
Oauth2RegisterNewParamsTokenEndpointAuthMethodClientSecretPost Oauth2RegisterNewParamsTokenEndpointAuthMethod = "client_secret_post"
Oauth2RegisterNewParamsTokenEndpointAuthMethodNone Oauth2RegisterNewParamsTokenEndpointAuthMethod = "none"
)
func (r Oauth2RegisterNewParamsTokenEndpointAuthMethod) IsKnown() bool {
switch r {
case Oauth2RegisterNewParamsTokenEndpointAuthMethodClientSecretBasic, Oauth2RegisterNewParamsTokenEndpointAuthMethodClientSecretPost, Oauth2RegisterNewParamsTokenEndpointAuthMethodNone:
return true
}
return false
}
type Oauth2RegisterUpdateParams struct {
PathClientID param.Field[string] `path:"client_id,required"`
BodyClientID param.Field[string] `json:"client_id,required"`
ClientName param.Field[string] `json:"client_name,required"`
RedirectUris param.Field[[]string] `json:"redirect_uris,required" format:"uri"`
ClientUri param.Field[string] `json:"client_uri"`
GrantTypes param.Field[[]Oauth2RegisterUpdateParamsGrantType] `json:"grant_types"`
LogoUri param.Field[string] `json:"logo_uri" format:"uri"`
PolicyUri param.Field[string] `json:"policy_uri" format:"uri"`
ResponseTypes param.Field[[]Oauth2RegisterUpdateParamsResponseType] `json:"response_types"`
Scope param.Field[string] `json:"scope"`
TokenEndpointAuthMethod param.Field[Oauth2RegisterUpdateParamsTokenEndpointAuthMethod] `json:"token_endpoint_auth_method"`
TosUri param.Field[string] `json:"tos_uri" format:"uri"`
}
func (r Oauth2RegisterUpdateParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type Oauth2RegisterUpdateParamsGrantType string
const (
Oauth2RegisterUpdateParamsGrantTypeAuthorizationCode Oauth2RegisterUpdateParamsGrantType = "authorization_code"
Oauth2RegisterUpdateParamsGrantTypeRefreshToken Oauth2RegisterUpdateParamsGrantType = "refresh_token"
)
func (r Oauth2RegisterUpdateParamsGrantType) IsKnown() bool {
switch r {
case Oauth2RegisterUpdateParamsGrantTypeAuthorizationCode, Oauth2RegisterUpdateParamsGrantTypeRefreshToken:
return true
}
return false
}
type Oauth2RegisterUpdateParamsResponseType string
const (
Oauth2RegisterUpdateParamsResponseTypeCode Oauth2RegisterUpdateParamsResponseType = "code"
)
func (r Oauth2RegisterUpdateParamsResponseType) IsKnown() bool {
switch r {
case Oauth2RegisterUpdateParamsResponseTypeCode:
return true
}
return false
}
type Oauth2RegisterUpdateParamsTokenEndpointAuthMethod string
const (
Oauth2RegisterUpdateParamsTokenEndpointAuthMethodClientSecretBasic Oauth2RegisterUpdateParamsTokenEndpointAuthMethod = "client_secret_basic"
Oauth2RegisterUpdateParamsTokenEndpointAuthMethodClientSecretPost Oauth2RegisterUpdateParamsTokenEndpointAuthMethod = "client_secret_post"
Oauth2RegisterUpdateParamsTokenEndpointAuthMethodNone Oauth2RegisterUpdateParamsTokenEndpointAuthMethod = "none"
)
func (r Oauth2RegisterUpdateParamsTokenEndpointAuthMethod) IsKnown() bool {
switch r {
case Oauth2RegisterUpdateParamsTokenEndpointAuthMethodClientSecretBasic, Oauth2RegisterUpdateParamsTokenEndpointAuthMethodClientSecretPost, Oauth2RegisterUpdateParamsTokenEndpointAuthMethodNone:
return true
}
return false
}