28 lines
781 B
Go
28 lines
781 B
Go
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")
|
|
}
|