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 package oauth2
57
58 import (
59 "bytes"
60 "context"
61 "encoding/json"
62 "errors"
63 "fmt"
64 "io"
65 "net/http"
66 "net/url"
67 "strconv"
68 "strings"
69
70 googleapi "google.golang.org/api/googleapi"
71 internal "google.golang.org/api/internal"
72 gensupport "google.golang.org/api/internal/gensupport"
73 option "google.golang.org/api/option"
74 internaloption "google.golang.org/api/option/internaloption"
75 htransport "google.golang.org/api/transport/http"
76 )
77
78
79
80 var _ = bytes.NewBuffer
81 var _ = strconv.Itoa
82 var _ = fmt.Sprintf
83 var _ = json.NewDecoder
84 var _ = io.Copy
85 var _ = url.Parse
86 var _ = gensupport.MarshalJSON
87 var _ = googleapi.Version
88 var _ = errors.New
89 var _ = strings.Replace
90 var _ = context.Canceled
91 var _ = internaloption.WithDefaultEndpoint
92 var _ = internal.Version
93
94 const apiId = "oauth2:v2"
95 const apiName = "oauth2"
96 const apiVersion = "v2"
97 const basePath = "https://www.googleapis.com/"
98 const basePathTemplate = "https://www.UNIVERSE_DOMAIN/"
99
100
101 const (
102
103 UserinfoEmailScope = "https://www.googleapis.com/auth/userinfo.email"
104
105
106
107 UserinfoProfileScope = "https://www.googleapis.com/auth/userinfo.profile"
108
109
110 OpenIDScope = "openid"
111 )
112
113
114 func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error) {
115 scopesOption := internaloption.WithDefaultScopes(
116 "https://www.googleapis.com/auth/userinfo.email",
117 "https://www.googleapis.com/auth/userinfo.profile",
118 "openid",
119 )
120
121 opts = append([]option.ClientOption{scopesOption}, opts...)
122 opts = append(opts, internaloption.WithDefaultEndpoint(basePath))
123 opts = append(opts, internaloption.WithDefaultEndpointTemplate(basePathTemplate))
124 opts = append(opts, internaloption.EnableNewAuthLibrary())
125 client, endpoint, err := htransport.NewClient(ctx, opts...)
126 if err != nil {
127 return nil, err
128 }
129 s, err := New(client)
130 if err != nil {
131 return nil, err
132 }
133 if endpoint != "" {
134 s.BasePath = endpoint
135 }
136 return s, nil
137 }
138
139
140
141
142
143
144 func New(client *http.Client) (*Service, error) {
145 if client == nil {
146 return nil, errors.New("client is nil")
147 }
148 s := &Service{client: client, BasePath: basePath}
149 s.Userinfo = NewUserinfoService(s)
150 return s, nil
151 }
152
153 type Service struct {
154 client *http.Client
155 BasePath string
156 UserAgent string
157
158 Userinfo *UserinfoService
159 }
160
161 func (s *Service) userAgent() string {
162 if s.UserAgent == "" {
163 return googleapi.UserAgent
164 }
165 return googleapi.UserAgent + " " + s.UserAgent
166 }
167
168 func NewUserinfoService(s *Service) *UserinfoService {
169 rs := &UserinfoService{s: s}
170 rs.V2 = NewUserinfoV2Service(s)
171 return rs
172 }
173
174 type UserinfoService struct {
175 s *Service
176
177 V2 *UserinfoV2Service
178 }
179
180 func NewUserinfoV2Service(s *Service) *UserinfoV2Service {
181 rs := &UserinfoV2Service{s: s}
182 rs.Me = NewUserinfoV2MeService(s)
183 return rs
184 }
185
186 type UserinfoV2Service struct {
187 s *Service
188
189 Me *UserinfoV2MeService
190 }
191
192 func NewUserinfoV2MeService(s *Service) *UserinfoV2MeService {
193 rs := &UserinfoV2MeService{s: s}
194 return rs
195 }
196
197 type UserinfoV2MeService struct {
198 s *Service
199 }
200
201 type Tokeninfo struct {
202
203
204 Audience string `json:"audience,omitempty"`
205
206
207 Email string `json:"email,omitempty"`
208
209
210 ExpiresIn int64 `json:"expires_in,omitempty"`
211
212 IssuedTo string `json:"issued_to,omitempty"`
213
214 Scope string `json:"scope,omitempty"`
215
216 UserId string `json:"user_id,omitempty"`
217
218
219 VerifiedEmail bool `json:"verified_email,omitempty"`
220
221
222 googleapi.ServerResponse `json:"-"`
223
224
225
226
227
228 ForceSendFields []string `json:"-"`
229
230
231
232
233 NullFields []string `json:"-"`
234 }
235
236 func (s *Tokeninfo) MarshalJSON() ([]byte, error) {
237 type NoMethod Tokeninfo
238 return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
239 }
240
241 type Userinfo struct {
242
243 Email string `json:"email,omitempty"`
244
245 FamilyName string `json:"family_name,omitempty"`
246
247 Gender string `json:"gender,omitempty"`
248
249 GivenName string `json:"given_name,omitempty"`
250
251 Hd string `json:"hd,omitempty"`
252
253 Id string `json:"id,omitempty"`
254
255 Link string `json:"link,omitempty"`
256
257 Locale string `json:"locale,omitempty"`
258
259 Name string `json:"name,omitempty"`
260
261 Picture string `json:"picture,omitempty"`
262
263
264
265
266 VerifiedEmail *bool `json:"verified_email,omitempty"`
267
268
269 googleapi.ServerResponse `json:"-"`
270
271
272
273
274
275 ForceSendFields []string `json:"-"`
276
277
278
279
280 NullFields []string `json:"-"`
281 }
282
283 func (s *Userinfo) MarshalJSON() ([]byte, error) {
284 type NoMethod Userinfo
285 return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
286 }
287
288 type TokeninfoCall struct {
289 s *Service
290 urlParams_ gensupport.URLParams
291 ctx_ context.Context
292 header_ http.Header
293 }
294
295
296 func (s *Service) Tokeninfo() *TokeninfoCall {
297 c := &TokeninfoCall{s: s, urlParams_: make(gensupport.URLParams)}
298 return c
299 }
300
301
302 func (c *TokeninfoCall) AccessToken(accessToken string) *TokeninfoCall {
303 c.urlParams_.Set("access_token", accessToken)
304 return c
305 }
306
307
308 func (c *TokeninfoCall) IdToken(idToken string) *TokeninfoCall {
309 c.urlParams_.Set("id_token", idToken)
310 return c
311 }
312
313
314
315
316 func (c *TokeninfoCall) Fields(s ...googleapi.Field) *TokeninfoCall {
317 c.urlParams_.Set("fields", googleapi.CombineFields(s))
318 return c
319 }
320
321
322 func (c *TokeninfoCall) Context(ctx context.Context) *TokeninfoCall {
323 c.ctx_ = ctx
324 return c
325 }
326
327
328
329 func (c *TokeninfoCall) Header() http.Header {
330 if c.header_ == nil {
331 c.header_ = make(http.Header)
332 }
333 return c.header_
334 }
335
336 func (c *TokeninfoCall) doRequest(alt string) (*http.Response, error) {
337 reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_)
338 var body io.Reader = nil
339 c.urlParams_.Set("alt", alt)
340 c.urlParams_.Set("prettyPrint", "false")
341 urls := googleapi.ResolveRelative(c.s.BasePath, "oauth2/v2/tokeninfo")
342 urls += "?" + c.urlParams_.Encode()
343 req, err := http.NewRequest("POST", urls, body)
344 if err != nil {
345 return nil, err
346 }
347 req.Header = reqHeaders
348 return gensupport.SendRequest(c.ctx_, c.s.client, req)
349 }
350
351
352
353
354
355
356 func (c *TokeninfoCall) Do(opts ...googleapi.CallOption) (*Tokeninfo, error) {
357 gensupport.SetOptions(c.urlParams_, opts...)
358 res, err := c.doRequest("json")
359 if res != nil && res.StatusCode == http.StatusNotModified {
360 if res.Body != nil {
361 res.Body.Close()
362 }
363 return nil, gensupport.WrapError(&googleapi.Error{
364 Code: res.StatusCode,
365 Header: res.Header,
366 })
367 }
368 if err != nil {
369 return nil, err
370 }
371 defer googleapi.CloseBody(res)
372 if err := googleapi.CheckResponse(res); err != nil {
373 return nil, gensupport.WrapError(err)
374 }
375 ret := &Tokeninfo{
376 ServerResponse: googleapi.ServerResponse{
377 Header: res.Header,
378 HTTPStatusCode: res.StatusCode,
379 },
380 }
381 target := &ret
382 if err := gensupport.DecodeResponse(target, res); err != nil {
383 return nil, err
384 }
385 return ret, nil
386 }
387
388 type UserinfoGetCall struct {
389 s *Service
390 urlParams_ gensupport.URLParams
391 ifNoneMatch_ string
392 ctx_ context.Context
393 header_ http.Header
394 }
395
396
397 func (r *UserinfoService) Get() *UserinfoGetCall {
398 c := &UserinfoGetCall{s: r.s, urlParams_: make(gensupport.URLParams)}
399 return c
400 }
401
402
403
404
405 func (c *UserinfoGetCall) Fields(s ...googleapi.Field) *UserinfoGetCall {
406 c.urlParams_.Set("fields", googleapi.CombineFields(s))
407 return c
408 }
409
410
411
412
413 func (c *UserinfoGetCall) IfNoneMatch(entityTag string) *UserinfoGetCall {
414 c.ifNoneMatch_ = entityTag
415 return c
416 }
417
418
419 func (c *UserinfoGetCall) Context(ctx context.Context) *UserinfoGetCall {
420 c.ctx_ = ctx
421 return c
422 }
423
424
425
426 func (c *UserinfoGetCall) Header() http.Header {
427 if c.header_ == nil {
428 c.header_ = make(http.Header)
429 }
430 return c.header_
431 }
432
433 func (c *UserinfoGetCall) doRequest(alt string) (*http.Response, error) {
434 reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_)
435 if c.ifNoneMatch_ != "" {
436 reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
437 }
438 var body io.Reader = nil
439 c.urlParams_.Set("alt", alt)
440 c.urlParams_.Set("prettyPrint", "false")
441 urls := googleapi.ResolveRelative(c.s.BasePath, "oauth2/v2/userinfo")
442 urls += "?" + c.urlParams_.Encode()
443 req, err := http.NewRequest("GET", urls, body)
444 if err != nil {
445 return nil, err
446 }
447 req.Header = reqHeaders
448 return gensupport.SendRequest(c.ctx_, c.s.client, req)
449 }
450
451
452
453
454
455
456 func (c *UserinfoGetCall) Do(opts ...googleapi.CallOption) (*Userinfo, error) {
457 gensupport.SetOptions(c.urlParams_, opts...)
458 res, err := c.doRequest("json")
459 if res != nil && res.StatusCode == http.StatusNotModified {
460 if res.Body != nil {
461 res.Body.Close()
462 }
463 return nil, gensupport.WrapError(&googleapi.Error{
464 Code: res.StatusCode,
465 Header: res.Header,
466 })
467 }
468 if err != nil {
469 return nil, err
470 }
471 defer googleapi.CloseBody(res)
472 if err := googleapi.CheckResponse(res); err != nil {
473 return nil, gensupport.WrapError(err)
474 }
475 ret := &Userinfo{
476 ServerResponse: googleapi.ServerResponse{
477 Header: res.Header,
478 HTTPStatusCode: res.StatusCode,
479 },
480 }
481 target := &ret
482 if err := gensupport.DecodeResponse(target, res); err != nil {
483 return nil, err
484 }
485 return ret, nil
486 }
487
488 type UserinfoV2MeGetCall struct {
489 s *Service
490 urlParams_ gensupport.URLParams
491 ifNoneMatch_ string
492 ctx_ context.Context
493 header_ http.Header
494 }
495
496
497 func (r *UserinfoV2MeService) Get() *UserinfoV2MeGetCall {
498 c := &UserinfoV2MeGetCall{s: r.s, urlParams_: make(gensupport.URLParams)}
499 return c
500 }
501
502
503
504
505 func (c *UserinfoV2MeGetCall) Fields(s ...googleapi.Field) *UserinfoV2MeGetCall {
506 c.urlParams_.Set("fields", googleapi.CombineFields(s))
507 return c
508 }
509
510
511
512
513 func (c *UserinfoV2MeGetCall) IfNoneMatch(entityTag string) *UserinfoV2MeGetCall {
514 c.ifNoneMatch_ = entityTag
515 return c
516 }
517
518
519 func (c *UserinfoV2MeGetCall) Context(ctx context.Context) *UserinfoV2MeGetCall {
520 c.ctx_ = ctx
521 return c
522 }
523
524
525
526 func (c *UserinfoV2MeGetCall) Header() http.Header {
527 if c.header_ == nil {
528 c.header_ = make(http.Header)
529 }
530 return c.header_
531 }
532
533 func (c *UserinfoV2MeGetCall) doRequest(alt string) (*http.Response, error) {
534 reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_)
535 if c.ifNoneMatch_ != "" {
536 reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
537 }
538 var body io.Reader = nil
539 c.urlParams_.Set("alt", alt)
540 c.urlParams_.Set("prettyPrint", "false")
541 urls := googleapi.ResolveRelative(c.s.BasePath, "userinfo/v2/me")
542 urls += "?" + c.urlParams_.Encode()
543 req, err := http.NewRequest("GET", urls, body)
544 if err != nil {
545 return nil, err
546 }
547 req.Header = reqHeaders
548 return gensupport.SendRequest(c.ctx_, c.s.client, req)
549 }
550
551
552
553
554
555
556 func (c *UserinfoV2MeGetCall) Do(opts ...googleapi.CallOption) (*Userinfo, error) {
557 gensupport.SetOptions(c.urlParams_, opts...)
558 res, err := c.doRequest("json")
559 if res != nil && res.StatusCode == http.StatusNotModified {
560 if res.Body != nil {
561 res.Body.Close()
562 }
563 return nil, gensupport.WrapError(&googleapi.Error{
564 Code: res.StatusCode,
565 Header: res.Header,
566 })
567 }
568 if err != nil {
569 return nil, err
570 }
571 defer googleapi.CloseBody(res)
572 if err := googleapi.CheckResponse(res); err != nil {
573 return nil, gensupport.WrapError(err)
574 }
575 ret := &Userinfo{
576 ServerResponse: googleapi.ServerResponse{
577 Header: res.Header,
578 HTTPStatusCode: res.StatusCode,
579 },
580 }
581 target := &ret
582 if err := gensupport.DecodeResponse(target, res); err != nil {
583 return nil, err
584 }
585 return ret, nil
586 }
587
View as plain text