forked from remote/oauth2
google: add CredentialsFromJSON
Support obtaining a DefaultCredentials value from JSON data. Also, add an example, and write more package doc. For Go 1.9 and higher, rename DefaultCredentials to Credentials and make the former an alias for the latter. Updates google/google-api-go-client#247. Change-Id: I9f9e234ed79f8e08fa13914d9c6c60e0154a06e5 Reviewed-on: https://go-review.googlesource.com/99795 Reviewed-by: Ross Light <light@google.com> Reviewed-by: Chris Broadfoot <cbro@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
committed by
Chris Broadfoot
parent
2f32c3ac0f
commit
7af32f14d0
@@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build appenginevm appengine
|
||||
|
||||
package google_test
|
||||
|
||||
import (
|
||||
@@ -12,6 +10,7 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
"golang.org/x/oauth2"
|
||||
"golang.org/x/oauth2/google"
|
||||
"golang.org/x/oauth2/jwt"
|
||||
@@ -148,3 +147,16 @@ func ExampleComputeTokenSource() {
|
||||
}
|
||||
client.Get("...")
|
||||
}
|
||||
|
||||
func ExampleCredentialsFromJSON() {
|
||||
ctx := context.Background()
|
||||
data, err := ioutil.ReadFile("/path/to/key-file.json")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
creds, err := google.CredentialsFromJSON(ctx, data, "https://www.googleapis.com/auth/bigquery")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
_ = creds // TODO: Use creds.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user