44 lines
858 B
Go
44 lines
858 B
Go
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("state", 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 {
|
|
return c.SendStatus(fiber.StatusInternalServerError)
|
|
}
|
|
|
|
|
|
return c.JSON(token)
|
|
})
|
|
|
|
app.Listen(":8000")
|
|
}
|