-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
10 additions
and
262 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,23 +51,6 @@ func Example_config() { | |
// start making authenticated requests. | ||
client := http.Client{Transport: t} | ||
client.Get("...") | ||
|
||
// Alternatively, you can initiate a new transport | ||
// with tokens from a cache. | ||
cache := oauth2.NewFileCache("/path/to/file") | ||
// NewTransportWithCache will try to read the cached | ||
// token, if any error occurs, it returns the error. | ||
// If a token is available at the cache, initiates | ||
// a new transport authorized and authenticated with | ||
// the read token. If token expires, and a new access | ||
// token is retrieved, it writes the newly fetched | ||
// token to the cache. | ||
t, err = conf.NewTransportWithCache(cache) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
client = http.Client{Transport: t} | ||
client.Get("...") | ||
} | ||
|
||
func Example_jWTConfig() { | ||
|
@@ -95,18 +78,4 @@ func Example_jWTConfig() { | |
// request will be made on the behalf of [email protected]. | ||
client = http.Client{Transport: conf.NewTransportWithUser("[email protected]")} | ||
client.Get("...") | ||
|
||
// Alternatively you can iniate a transport with | ||
// a token read from the cache. | ||
// If the existing access token expires, and a new access token is | ||
// retrieved, the newly fetched token will be written to the cache. | ||
cache := oauth2.NewFileCache("/path/to/file") | ||
t, err := conf.NewTransportWithCache(cache) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
client = http.Client{Transport: t} | ||
// The following request will be authorized by the token | ||
// retrieved from the cache. | ||
client.Get("...") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,23 +45,6 @@ func Example_webServer() { | |
} | ||
client := http.Client{Transport: t} | ||
client.Get("...") | ||
|
||
// Alternatively you can initiate a new transport | ||
// with a token from a cache. | ||
cache := oauth2.NewFileCache("/path/to/file") | ||
// NewTransportWithCache will try to read the cached | ||
// token, if any error occurs, it returns the error. | ||
// If a token is available at the cache, initiates | ||
// a new transport authorized and authenticated with | ||
// the read token. If token expires, and a new access | ||
// token is retrieved, it writes the newly fetched | ||
// token to the cache. | ||
t, err = config.NewTransportWithCache(cache) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
client = http.Client{Transport: t} | ||
client.Get("...") | ||
} | ||
|
||
func Example_serviceAccounts() { | ||
|
@@ -92,20 +75,6 @@ func Example_serviceAccounts() { | |
// request will be made on the behalf of [email protected]. | ||
client = http.Client{Transport: config.NewTransportWithUser("[email protected]")} | ||
client.Get("...") | ||
|
||
// Alternatively you can iniate a transport with | ||
// a token read from the cache. | ||
// If the existing access token expires, and a new access token is | ||
// retrieved, the newly fetched token will be written to the cache. | ||
cache := oauth2.NewFileCache("/path/to/file") | ||
t, err := config.NewTransportWithCache(cache) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
client = http.Client{Transport: t} | ||
// The following request will be authorized by the token | ||
// retrieved from the cache. | ||
client.Get("...") | ||
} | ||
|
||
func Example_appEngine() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
93ad3f4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, can I ask why this was removed? I'm seeing a lot of people trying to make oauth2 do this kind of thing and having trouble (me included). What's the right way to cache tokens now? Thanks!
93ad3f4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was removed because it's not an API that we want to support. We need to revisit caching and design a nicer way of doing it. I think it would be something like a
CachingTokenSource
whose constructor takes aTokenCache
.cc @broady @bradfitz
93ad3f4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@johnl I think is better to remove it, I dont use this, for me is better to cache the tokens in Memcache that in files.
93ad3f4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adg There is no point of polluting the APIs. Users must wrap the RoundTripper to cache. We must document it by providing a sample. If you would like to contribute a sample, I can review.
93ad3f4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A wrapper for
TokenSource
can provide caching. +1 for a code sample.ReuseTokenSource
is a good example.https://github.com/golang/oauth2/blob/master/oauth2.go#L310
93ad3f4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move this to a bug.
93ad3f4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #84.