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