| // Copyright 2023 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| package main |
| |
| import ( |
| "context" |
| "fmt" |
| "os" |
| "time" |
| |
| "go.chromium.org/luci/auth" |
| "go.chromium.org/luci/hardcoded/chromeinfra" |
| ) |
| |
| func main() { |
| ctx := context.Background() |
| opts := chromeinfra.DefaultAuthOptions() |
| opts.Scopes = []string{ |
| "https://www.googleapis.com/auth/cloud-platform", |
| "https://www.googleapis.com/auth/devstorage.read_write", |
| "https://www.googleapis.com/auth/userinfo.email", |
| } |
| authenticator := auth.NewAuthenticator(ctx, auth.SilentLogin, opts) |
| token, err := authenticator.GetAccessToken(4 * time.Minute) |
| if err != nil { |
| fmt.Fprintf(os.Stderr, "Error getting access token: %v\n", err) |
| os.Exit(1) |
| return |
| } |
| fmt.Println(token.AccessToken) |
| os.Exit(0) |
| } |