|
| 1 | +package commands |
| 2 | + |
| 3 | +import ( |
| 4 | + "bufio" |
| 5 | + "fmt" |
| 6 | + "os" |
| 7 | + "strings" |
| 8 | +) |
| 9 | + |
| 10 | +type RegisterCmd struct{} |
| 11 | + |
| 12 | +func (c *RegisterCmd) Run(args []string) error { |
| 13 | + fmt.Fprintln(os.Stderr, "Basecamp OAuth App Registration Helper") |
| 14 | + fmt.Fprintln(os.Stderr, strings.Repeat("=", 40)) |
| 15 | + fmt.Fprintln(os.Stderr) |
| 16 | + fmt.Fprintln(os.Stderr, "This helper will generate the values you need to register") |
| 17 | + fmt.Fprintln(os.Stderr, "your Basecamp OAuth application.") |
| 18 | + fmt.Fprintln(os.Stderr) |
| 19 | + |
| 20 | + reader := bufio.NewReader(os.Stdin) |
| 21 | + |
| 22 | + appName := prompt(reader, "Application name", "My Basecamp CLI") |
| 23 | + companyName := prompt(reader, "Company/Organization name", "") |
| 24 | + websiteURL := prompt(reader, "Website URL", "https://github.com/robzolkos/basecamp-cli") |
| 25 | + accessibleURL := prompt(reader, "URL where this computer is accessible (e.g., https://myhost.tailscale.ts.net)", "") |
| 26 | + |
| 27 | + // Build redirect URI from accessible URL |
| 28 | + redirectURI := buildRedirectURI(accessibleURL) |
| 29 | + |
| 30 | + fmt.Fprintln(os.Stderr) |
| 31 | + fmt.Fprintln(os.Stderr, strings.Repeat("=", 60)) |
| 32 | + fmt.Fprintln(os.Stderr, "REGISTRATION INSTRUCTIONS") |
| 33 | + fmt.Fprintln(os.Stderr, strings.Repeat("=", 60)) |
| 34 | + fmt.Fprintln(os.Stderr) |
| 35 | + fmt.Fprintln(os.Stderr, "1. Visit: https://launchpad.37signals.com/integrations") |
| 36 | + fmt.Fprintln(os.Stderr) |
| 37 | + fmt.Fprintln(os.Stderr, "2. Click 'Register another application'") |
| 38 | + fmt.Fprintln(os.Stderr) |
| 39 | + fmt.Fprintln(os.Stderr, "3. Fill out the form with these values:") |
| 40 | + fmt.Fprintln(os.Stderr) |
| 41 | + fmt.Fprintf(os.Stderr, " Name of your application: %s\n", appName) |
| 42 | + fmt.Fprintf(os.Stderr, " Your company/organization: %s\n", companyName) |
| 43 | + fmt.Fprintf(os.Stderr, " Website URL: %s\n", websiteURL) |
| 44 | + fmt.Fprintf(os.Stderr, " Redirect URI: %s\n", redirectURI) |
| 45 | + fmt.Fprintln(os.Stderr) |
| 46 | + fmt.Fprintln(os.Stderr, "4. After registering, copy your Client ID and Client Secret") |
| 47 | + fmt.Fprintln(os.Stderr) |
| 48 | + fmt.Fprintln(os.Stderr, "5. Run 'basecamp init' and enter the credentials when prompted") |
| 49 | + fmt.Fprintln(os.Stderr, " (use the same Redirect URI shown above)") |
| 50 | + fmt.Fprintln(os.Stderr) |
| 51 | + fmt.Fprintln(os.Stderr, "6. Run 'basecamp auth' to authenticate") |
| 52 | + fmt.Fprintln(os.Stderr, strings.Repeat("=", 60)) |
| 53 | + |
| 54 | + return PrintJSON(map[string]string{ |
| 55 | + "application_name": appName, |
| 56 | + "company_name": companyName, |
| 57 | + "website_url": websiteURL, |
| 58 | + "redirect_uri": redirectURI, |
| 59 | + "registration_url": "https://launchpad.37signals.com/integrations", |
| 60 | + }) |
| 61 | +} |
| 62 | + |
| 63 | +func buildRedirectURI(accessibleURL string) string { |
| 64 | + if accessibleURL == "" { |
| 65 | + return "http://localhost:3002/callback" |
| 66 | + } |
| 67 | + |
| 68 | + // Remove trailing slash if present |
| 69 | + accessibleURL = strings.TrimSuffix(accessibleURL, "/") |
| 70 | + |
| 71 | + // Add port and callback path |
| 72 | + return accessibleURL + ":3002/callback" |
| 73 | +} |
0 commit comments