Skip to content

Commit

Permalink
add a way to invite the bot
Browse files Browse the repository at this point in the history
  • Loading branch information
merlinfuchs committed Feb 4, 2024
1 parent 02d8b62 commit 9a476bd
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 5 deletions.
4 changes: 2 additions & 2 deletions kite-service/cmd/config/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ func loginCMD() *cli.Command {
Flags: []cli.Flag{
&cli.StringFlag{
Name: "server",
Usage: "The Kite server to deploy to",
Value: "http://localhost:8080",
Usage: "The Kite server to authenticate with",
Value: "https://api.kite.onl",
},
},
Action: func(c *cli.Context) error {
Expand Down
2 changes: 1 addition & 1 deletion kite-service/cmd/plugin/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func deployCMD() *cli.Command {
&cli.StringFlag{
Name: "server",
Usage: "The Kite server to deploy to",
Value: "http://localhost:8080",
Value: "https://api.kite.onl",
},
},
Action: func(c *cli.Context) error {
Expand Down
1 change: 1 addition & 0 deletions kite-service/internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func (api *API) RegisterHandlers(engine *engine.Engine, pg *postgres.Client, acc
v1Group := api.app.Group("/v1")

authHandler := auth.New(sessionManager, pg, cfg)
v1Group.Get("/auth/invite", authHandler.HandleAuthInviteRedirect)
v1Group.Get("/auth/redirect", authHandler.HandleAuthRedirect)
v1Group.Get("/auth/callback", authHandler.HandleAuthCallback)
v1Group.Get("/auth/logout", authHandler.HandleAuthLogout)
Expand Down
13 changes: 12 additions & 1 deletion kite-service/internal/api/handler/auth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ func New(sessionManager *session.SessionManager, userStore store.UserStore, cfg
}
}

func (h *AuthHandler) HandleAuthInviteRedirect(c *fiber.Ctx) error {
oauth2Config := *h.oauth2Config
oauth2Config.Scopes = append(oauth2Config.Scopes, discord.ScopeBot, discord.ScopeApplicationsCommands)

state := setOauthStateCookie(c)
url := oauth2Config.AuthCodeURL(state)
// TODO: add permissions?

return c.Redirect(url, http.StatusTemporaryRedirect)
}

func (h *AuthHandler) HandleAuthRedirect(c *fiber.Ctx) error {
state := setOauthStateCookie(c)
return c.Redirect(h.oauth2Config.AuthCodeURL(state), http.StatusTemporaryRedirect)
Expand All @@ -74,7 +85,7 @@ func (h *AuthHandler) HandleAuthCallback(c *fiber.Ctx) error {
return err
}

return c.Redirect(h.cfg.App.AuthCallbackURL(), http.StatusTemporaryRedirect)
return c.Redirect(h.cfg.App.AuthCallbackURL()+"/app", http.StatusTemporaryRedirect)
}

func (h *AuthHandler) HandleAuthLogout(c *fiber.Ctx) error {
Expand Down
2 changes: 1 addition & 1 deletion kite-web/public/illustrations/wip.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions kite-web/src/pages/app/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import AppLayout from "@/components/app/AppLayout";
import { getApiUrl } from "@/lib/api/client";
import { useGuildsQuery } from "@/lib/api/queries";
import { guildIconUrl } from "@/lib/discord/cdn";
import { guildNameAbbreviation } from "@/lib/discord/util";
import { PlusCircleIcon } from "@heroicons/react/24/outline";
import Link from "next/link";

export default function GuildsPage() {
Expand Down Expand Up @@ -48,6 +50,15 @@ export default function GuildsPage() {
</div>
</Link>
))}
<a
className="rounded-md px-3 py-3 border-2 border-dashed border-dark-7 hover:bg-dark-4 flex items-center"
href={getApiUrl("/v1/auth/invite")}
>
<PlusCircleIcon className="h-14 w-14 text-gray-300 mr-3" />
<div className="text-lg font-medium text-gray-100">
Add to server
</div>
</a>
</div>
</div>
</AppLayout>
Expand Down

0 comments on commit 9a476bd

Please sign in to comment.