downscope: update examples

This commit is contained in:
Patrick Jones
2021-08-04 14:38:56 -07:00
parent e1c4f01528
commit db8a13916c
3 changed files with 15 additions and 20 deletions

View File

@@ -7,14 +7,13 @@ package downscope_test
import (
"context"
"fmt"
"golang.org/x/oauth2/google"
"golang.org/x/oauth2"
"golang.org/x/oauth2/google/downscope"
)
func ExampleNewTokenSource() {
// This shows how to generate a downscoped token. This code would be run on the
// token broker, which holds the root token used to generate the downscoped token.
@@ -48,9 +47,9 @@ func ExampleNewTokenSource() {
// You can now pass tok to a token consumer however you wish, such as exposing
// a REST API and sending it over HTTP.
// You can instead use the token held in myTokenSource to make
// You can instead use the token held in dts to make
// Google Cloud Storage calls, as follows:
// storageClient, err := storage.NewClient(ctx, option.WithTokenSource(myTokenSource))
// storageClient, err := storage.NewClient(ctx, option.WithTokenSource(dts))
}

View File

@@ -5,7 +5,6 @@ import (
)
type localTokenSource struct {
requestedPerms []string
requestedObject string
brokerURL string
}
@@ -16,7 +15,6 @@ func (localTokenSource) Token() (*oauth2.Token, error){
return &remoteToken, nil
}
func Example() {
// A token consumer should define their own tokenSource. In the Token() method,
// it should send a query to a token broker requesting a downscoped token.
@@ -24,7 +22,6 @@ func Example() {
// downscoped token.
thisTokenSource := localTokenSource{
requestedPerms: []string{"inRole:roles/storage.objectViewer"},
requestedObject: "//storage.googleapis.com/projects/_/buckets/foo",
brokerURL: "yourURL.com/internal/broker",
}
@@ -32,11 +29,10 @@ func Example() {
// Wrap the TokenSource in an oauth2.ReuseTokenSource to enable automatic refreshing
refreshableTS := oauth2.ReuseTokenSource(nil, thisTokenSource)
// You can now use the token source to access Google Cloud Storage resources as follows.
// storageClient, err := storage.NewClient(ctx, option.WithTokenSource(refreshableTS))
// bkt := storageClient.Bucket(bucketName)
// bkt := storageClient.Bucket("foo"")
// obj := bkt.Object(objectName)
// rc, err := obj.NewReader(ctx)
// defer rc.Close()