1 // Copyright 2018 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
7 // This file applies to App Engine first generation runtimes (<= Go 1.9).
18 "google.golang.org/appengine"
22 appengineTokenFunc = appengine.AccessToken
23 appengineAppIDFunc = appengine.AppID
26 // See comment on AppEngineTokenSource in appengine.go.
27 func appEngineTokenSource(ctx context.Context, scope ...string) oauth2.TokenSource {
28 scopes := append([]string{}, scope...)
30 return &gaeTokenSource{
33 key: strings.Join(scopes, " "),
37 // aeTokens helps the fetched tokens to be reused until their expiration.
40 aeTokens = make(map[string]*tokenLock) // key is space-separated scopes
43 type tokenLock struct {
44 mu sync.Mutex // guards t; held while fetching or updating t
48 type gaeTokenSource struct {
51 key string // to aeTokens map; space-separated scopes
54 func (ts *gaeTokenSource) Token() (*oauth2.Token, error) {
56 tok, ok := aeTokens[ts.key]
59 aeTokens[ts.key] = tok
68 access, exp, err := appengineTokenFunc(ts.ctx, ts.scopes...)
72 tok.t = &oauth2.Token{