forked from Mirrors/oauth2
Add docs.
This commit is contained in:
parent
a443e46636
commit
7a2df5bea3
|
@ -9,20 +9,28 @@ import (
|
||||||
"github.com/golang/oauth2"
|
"github.com/golang/oauth2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// AppEngineConfig represents a configuration for an
|
||||||
|
// App Engine application's Google service account.
|
||||||
type AppEngineConfig struct {
|
type AppEngineConfig struct {
|
||||||
context appengine.Context
|
context appengine.Context
|
||||||
scopes []string
|
scopes []string
|
||||||
cache oauth2.Cache
|
cache oauth2.Cache
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewAppEngineConfig creates a new AppEngineConfig for the
|
||||||
|
// provided auth scopes.
|
||||||
func NewAppEngineConfig(context appengine.Context, scopes []string) *AppEngineConfig {
|
func NewAppEngineConfig(context appengine.Context, scopes []string) *AppEngineConfig {
|
||||||
return &AppEngineConfig{context: context, scopes: scopes}
|
return &AppEngineConfig{context: context, scopes: scopes}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewTransport returns a transport that authorizes
|
||||||
|
// the requests with the application's service account.
|
||||||
func (c *AppEngineConfig) NewTransport() oauth2.Transport {
|
func (c *AppEngineConfig) NewTransport() oauth2.Transport {
|
||||||
return oauth2.NewAuthorizedTransport(c, nil)
|
return oauth2.NewAuthorizedTransport(c, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewTransport returns a token-caching transport that authorizes
|
||||||
|
// the requests with the application's service account.
|
||||||
func (c *AppEngineConfig) NewTransportWithCache(cache oauth2.Cache) (oauth2.Transport, error) {
|
func (c *AppEngineConfig) NewTransportWithCache(cache oauth2.Cache) (oauth2.Transport, error) {
|
||||||
token, err := cache.Read()
|
token, err := cache.Read()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -32,6 +40,7 @@ func (c *AppEngineConfig) NewTransportWithCache(cache oauth2.Cache) (oauth2.Tran
|
||||||
return oauth2.NewAuthorizedTransport(c, token), nil
|
return oauth2.NewAuthorizedTransport(c, token), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FetchToken fetches a new access token for the provided scopes.
|
||||||
func (c *AppEngineConfig) FetchToken(existing *oauth2.Token) (*oauth2.Token, error) {
|
func (c *AppEngineConfig) FetchToken(existing *oauth2.Token) (*oauth2.Token, error) {
|
||||||
token, expiry, err := appengine.AccessToken(c.context, strings.Join(c.scopes, " "))
|
token, expiry, err := appengine.AccessToken(c.context, strings.Join(c.scopes, " "))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -9,20 +9,28 @@ import (
|
||||||
"google.golang.org/appengine"
|
"google.golang.org/appengine"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// AppEngineConfig represents a configuration for an
|
||||||
|
// App Engine application's Google service account.
|
||||||
type AppEngineConfig struct {
|
type AppEngineConfig struct {
|
||||||
context appengine.Context
|
context appengine.Context
|
||||||
scopes []string
|
scopes []string
|
||||||
cache oauth2.Cache
|
cache oauth2.Cache
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewAppEngineConfig creates a new AppEngineConfig for the
|
||||||
|
// provided auth scopes.
|
||||||
func NewAppEngineConfig(context appengine.Context, scopes []string) *AppEngineConfig {
|
func NewAppEngineConfig(context appengine.Context, scopes []string) *AppEngineConfig {
|
||||||
return &AppEngineConfig{context: context, scopes: scopes}
|
return &AppEngineConfig{context: context, scopes: scopes}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewTransport returns a transport that authorizes
|
||||||
|
// the requests with the application's service account.
|
||||||
func (c *AppEngineConfig) NewTransport() oauth2.Transport {
|
func (c *AppEngineConfig) NewTransport() oauth2.Transport {
|
||||||
return oauth2.NewAuthorizedTransport(c, nil)
|
return oauth2.NewAuthorizedTransport(c, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewTransport returns a token-caching transport that authorizes
|
||||||
|
// the requests with the application's service account.
|
||||||
func (c *AppEngineConfig) NewTransportWithCache(cache oauth2.Cache) (oauth2.Transport, error) {
|
func (c *AppEngineConfig) NewTransportWithCache(cache oauth2.Cache) (oauth2.Transport, error) {
|
||||||
token, err := cache.Read()
|
token, err := cache.Read()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -32,6 +40,7 @@ func (c *AppEngineConfig) NewTransportWithCache(cache oauth2.Cache) (oauth2.Tran
|
||||||
return oauth2.NewAuthorizedTransport(c, token), nil
|
return oauth2.NewAuthorizedTransport(c, token), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FetchToken fetches a new access token for the provided scopes.
|
||||||
func (c *AppEngineConfig) FetchToken(existing *oauth2.Token) (*oauth2.Token, error) {
|
func (c *AppEngineConfig) FetchToken(existing *oauth2.Token) (*oauth2.Token, error) {
|
||||||
token, expiry, err := appengine.AccessToken(c.context, strings.Join(c.scopes, " "))
|
token, expiry, err := appengine.AccessToken(c.context, strings.Join(c.scopes, " "))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue