Example #1
0
// FetchToken fetches a new access token for the provided scopes.
func (c *AppEngineConfig) FetchToken(existing *oauth2.Token) (*oauth2.Token, error) {
	token, expiry, err := appengine.AccessToken(c.context, c.scopes...)
	if err != nil {
		return nil, err
	}
	return &oauth2.Token{
		AccessToken: token,
		Expiry:      expiry,
	}, nil
}
// AccessToken implements Authenticator interface
func (a *GAEAppAuthenticator) AccessToken(http.RoundTripper) (string, error) {
	gaeAppTokenMu.Lock()
	defer gaeAppTokenMu.Unlock()

	if gaeAppToken == nil || !gaeAppToken.Valid() {
		token, expiry, err := appengine.AccessToken(a.ctx, identitytoolkitScope)
		if err != nil {
			return "", err
		}
		gaeAppToken = &oauth2.Token{
			AccessToken: token,
			Expiry:      expiry,
		}
	}
	return gaeAppToken.AccessToken, nil
}
Example #3
0
import (
	"time"

	"golang.org/x/net/context"
	"golang.org/x/oauth2"
	"google.golang.org/appengine"
)

// AppEngineTokenSource returns a token source that fetches tokens
// issued to the current App Engine application's service account.
// If you are implementing a 3-legged OAuth 2.0 flow on App Engine
// that involves user accounts, see oauth2.Config instead.
//
// The provided context must have come from appengine.NewContext.
func AppEngineTokenSource(ctx oauth2.Context, scope ...string) oauth2.TokenSource {
	return &appEngineTokenSource{
		ctx:         ctx,
		scopes:      scope,
		fetcherFunc: aeVMFetcherFunc,
	}
}

var aeVMFetcherFunc = func(ctx oauth2.Context, scope ...string) (string, time.Time, error) {
	c, ok := ctx.(context.Context)
	if !ok {
		return "", time.Time{}, errInvalidContext
	}
	return appengine.AccessToken(c, scope...)
}
Example #4
0
func (g giImpl) AccessToken(scopes ...string) (token string, expiry time.Time, err error) {
	return appengine.AccessToken(g.aeCtx, scopes...)
}