feat: add token file and env Login

This commit is contained in:
2026-09-01 11:53:16 -05:00
parent 076c8c81b8
commit 3983d0b335
5 changed files with 170 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
package auth
import (
"context"
"fmt"
"os"
)
// Login authenticates to Robinhood Agentic MCP and writes tokens.
// Prefers ROBINHOOD_ACCESS_TOKEN when set; otherwise runs a browser OAuth dance.
// Returns the Agentic account number when it can be discovered.
func Login(ctx context.Context, cfg Config) (accountID string, err error) {
if err := ctx.Err(); err != nil {
return "", err
}
cfg = cfg.WithDefaults()
if cfg.TokenFile == "" {
return "", fmt.Errorf("login: missing TokenFile")
}
if tok := os.Getenv("ROBINHOOD_ACCESS_TOKEN"); tok != "" {
if err := WriteTokens(cfg.TokenFile, tok, os.Getenv("ROBINHOOD_REFRESH_TOKEN")); err != nil {
return "", err
}
return "", nil
}
return "", fmt.Errorf("login: no ROBINHOOD_ACCESS_TOKEN and oauth not wired")
}