2014-09-03 14:50:43 -04:00
|
|
|
// Copyright 2014 The oauth2 Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2015-01-16 14:23:54 -05:00
|
|
|
// +build appengine
|
2014-06-17 09:53:08 -04:00
|
|
|
|
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
2014-10-03 01:44:50 -04:00
|
|
|
"time"
|
2014-09-02 17:06:51 -04:00
|
|
|
|
2014-07-09 01:27:34 -04:00
|
|
|
"appengine"
|
2014-10-03 01:44:50 -04:00
|
|
|
|
2014-12-11 02:30:13 -05:00
|
|
|
"golang.org/x/oauth2"
|
2014-11-06 19:36:41 -05:00
|
|
|
)
|
2014-10-03 01:44:50 -04:00
|
|
|
|
2014-12-11 02:30:13 -05:00
|
|
|
// 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.
|
|
|
|
//
|
2015-01-22 00:09:47 -05:00
|
|
|
// The provided context must have come from appengine.NewContext.
|
2015-01-16 14:23:54 -05:00
|
|
|
func AppEngineTokenSource(ctx oauth2.Context, scope ...string) oauth2.TokenSource {
|
2014-12-11 02:30:13 -05:00
|
|
|
return &appEngineTokenSource{
|
|
|
|
ctx: ctx,
|
|
|
|
scopes: scope,
|
|
|
|
fetcherFunc: aeFetcherFunc,
|
2014-08-31 18:13:59 -04:00
|
|
|
}
|
2014-06-17 09:53:08 -04:00
|
|
|
}
|
|
|
|
|
2014-12-11 02:30:13 -05:00
|
|
|
var aeFetcherFunc = func(ctx oauth2.Context, scope ...string) (string, time.Time, error) {
|
|
|
|
c, ok := ctx.(appengine.Context)
|
|
|
|
if !ok {
|
|
|
|
return "", time.Time{}, errInvalidContext
|
2014-10-03 01:44:50 -04:00
|
|
|
}
|
2014-12-11 02:30:13 -05:00
|
|
|
return appengine.AccessToken(c, scope...)
|
2014-09-02 17:06:51 -04:00
|
|
|
}
|