package main import ( "fmt" "log/slog" "os" "github.com/SphericalKat/whoop/whoop" "github.com/gofiber/fiber/v2" "golang.org/x/oauth2" ) func main() { oauthConf, err := whoop.InjectOauthConfig() if err != nil { slog.Error("error injecting oauth config", "err", err) os.Exit(1) } app := fiber.New(fiber.Config{ DisableStartupMessage: true, }) url := oauthConf.WhoopLoginConfig.AuthCodeURL("a5080d6b05b3", oauth2.AccessTypeOffline) fmt.Println("Visit the URL for the auth dialog: ", url) app.Get("/oauth2/callback", func(c *fiber.Ctx) error { code := c.Query("code") if code == "" { return c.SendStatus(fiber.StatusBadRequest) } token, err := oauthConf.WhoopLoginConfig.Exchange(c.Context(), code) if err != nil { slog.Error("error exchanging code for token", "err", err) return c.SendStatus(fiber.StatusInternalServerError) } return c.JSON(token) }) app.Listen(":8080") }