issues

Github, Jira, Gitlab issues from Plan 9's acme
Log | Files | Refs | README | LICENSE

commit d235292a981a94a4cf2321a8e15680dacfe4d672
parent ed6fefbc088e652fe383ae1ded8083c51dff79d5
Author: Russ Cox <rsc@golang.org>
Date:   Thu, 18 Jan 2024 16:29:25 -0800

internal/minutes2: delete old oauth2 code

Diffstat:
Minternal/minutes2/gdoc.go | 71++---------------------------------------------------------------------
1 file changed, 2 insertions(+), 69 deletions(-)

diff --git a/internal/minutes2/gdoc.go b/internal/minutes2/gdoc.go @@ -5,23 +5,19 @@ package main import ( - "context" "encoding/json" - "fmt" "log" "net/http" "os" "strconv" "strings" - "golang.org/x/oauth2" - "golang.org/x/oauth2/google" "google.golang.org/api/docs/v1" "google.golang.org/api/option" "rsc.io/oauthprompt" ) -func getClient(_ *oauth2.Config) *http.Client { +func getClient() *http.Client { tokFile := "/Users/rsc/.cred/minutes2.json" client, err := oauthprompt.GoogleToken(tokFile, "512347153416-eehjrr21snt0av7n1opjsorg889fcged.apps.googleusercontent.com", "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", "https://www.googleapis.com/auth/documents") if err != nil { @@ -30,58 +26,6 @@ func getClient(_ *oauth2.Config) *http.Client { return client } -// Retrieves a token, saves the token, then returns the generated client. -func XgetClient(config *oauth2.Config) *http.Client { - tokFile := "/Users/rsc/.cred/gdoc-token.json" - tok, err := tokenFromFile(tokFile) - if err != nil { - tok = getTokenFromWeb(config) - saveToken(tokFile, tok) - } - return config.Client(context.Background(), tok) -} - -// Requests a token from the web, then returns the retrieved token. -func getTokenFromWeb(config *oauth2.Config) *oauth2.Token { - authURL := config.AuthCodeURL("state-token", oauth2.AccessTypeOffline) - fmt.Fprintf(os.Stderr, "Go to the following link in your browser then type the "+ - "authorization code: \n%v\n", authURL) - - var authCode string - if _, err := fmt.Scan(&authCode); err != nil { - log.Fatalf("Unable to read authorization code: %v", err) - } - - tok, err := config.Exchange(oauth2.NoContext, authCode) - if err != nil { - log.Fatalf("Unable to retrieve token from web: %v", err) - } - return tok -} - -// Retrieves a token from a local file. -func tokenFromFile(file string) (*oauth2.Token, error) { - f, err := os.Open(file) - defer f.Close() - if err != nil { - return nil, err - } - tok := &oauth2.Token{} - err = json.NewDecoder(f).Decode(tok) - return tok, err -} - -// Saves a token to a file path. -func saveToken(path string, token *oauth2.Token) { - fmt.Fprintf(os.Stderr, "Saving credential file to: %s\n", path) - f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600) - defer f.Close() - if err != nil { - log.Fatalf("Unable to cache OAuth token: %v", err) - } - json.NewEncoder(f).Encode(token) -} - type Doc struct { Text []string // top-level text Who []string @@ -100,18 +44,7 @@ type Issue struct { func parseDoc() *Doc { var doc *docs.Document if true { - ctx := context.Background() - b, err := os.ReadFile("/Users/rsc/.cred/gdoc-cred.json") - if err != nil { - log.Fatalf("Unable to read client secret file: %v", err) - } - - // If modifying these scopes, delete your previously saved token.json. - config, err := google.ConfigFromJSON(b, "https://www.googleapis.com/auth/documents") - if err != nil { - log.Fatalf("Unable to parse client secret file to config: %v", err) - } - client := getClient(config) + client := getClient() srv, err := docs.NewService(ctx, option.WithHTTPClient(client)) if err != nil {