downscope: update documentation

This commit is contained in:
Patrick Jones
2021-07-29 13:38:18 -07:00
parent 941cf10a8e
commit c9764790d5
2 changed files with 36 additions and 3 deletions

View File

@@ -6,11 +6,16 @@ package downscope_test
import (
"context"
"fmt"
"golang.org/x/oauth2"
"golang.org/x/oauth2/google/downscope"
)
func Example() {
}
func ExampleNewTokenSource() {
ctx := context.Background()
// Initializes an accessBoundary with one Rule.
@@ -29,8 +34,12 @@ func ExampleNewTokenSource() {
dts, err := downscope.NewTokenSource(ctx, downscope.DownscopingConfig{RootSource: rootSource, Rules: accessBoundary})
if err != nil {
_ = dts
fmt.Printf("failed to generate downscoped token source: %v", err)
}
// Enables automatic token refreshing
_ := oauth2.ReuseTokenSource(nil, dts)
// You can now use the token held in myTokenSource to make
// Google Cloud Storage calls, as follows: