go.fuchsia.dev/infra@v0.0.0-20240507153436-9b593402251b/cmd/ffxluciauth/main.go (about) 1 // Copyright 2023 The Fuchsia Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 package main 5 6 import ( 7 "context" 8 "fmt" 9 "os" 10 "time" 11 12 "go.chromium.org/luci/auth" 13 "go.chromium.org/luci/hardcoded/chromeinfra" 14 ) 15 16 func main() { 17 ctx := context.Background() 18 opts := chromeinfra.DefaultAuthOptions() 19 opts.Scopes = []string{ 20 "https://www.googleapis.com/auth/cloud-platform", 21 "https://www.googleapis.com/auth/devstorage.read_write", 22 "https://www.googleapis.com/auth/userinfo.email", 23 } 24 authenticator := auth.NewAuthenticator(ctx, auth.SilentLogin, opts) 25 token, err := authenticator.GetAccessToken(4 * time.Minute) 26 if err != nil { 27 fmt.Fprintf(os.Stderr, "Error getting access token: %v\n", err) 28 os.Exit(1) 29 return 30 } 31 fmt.Println(token.AccessToken) 32 os.Exit(0) 33 }