Documentation
¶
Overview ¶
Package hibirafiber connects Hibira to Fiber (v3): channel authorization and user sign-in endpoints for pusher-js, webhook and Approvals callback receivers, and a waiting room middleware. Your functions get the fiber.Ctx, so whatever your auth middleware stored in Locals is at hand.
client := hibira.FromEnv()
app := fiber.New()
g := app.Group("/hibira", requireLogin)
g.Post("/auth", hibirafiber.Auth(client, func(c fiber.Ctx, channel string) (bool, *hibira.Member) {
u := c.Locals("user").(*User)
if channel == "private-user-"+u.ID {
return true, nil
}
return strings.HasPrefix(channel, "presence-room-"), &hibira.Member{UserID: u.ID, UserInfo: fiber.Map{"name": u.Name}}
}))
g.Post("/user-auth", hibirafiber.UserAuth(client, func(c fiber.Ctx) *hibira.User {
return &hibira.User{ID: c.Locals("user").(*User).ID}
}))
app.Post("/hibira/webhook", hibirafiber.Webhook(client, onWebhook))
app.Get("/drop", hibirafiber.WaitingRoom(room), dropPage)
On Fiber v2, mount the net/http handlers of github.com/hibira-io/go with the adaptor middleware (adaptor.HTTPHandler).
Index ¶
- Constants
- func ApprovalCallback(secret string, fn func(c fiber.Ctx, e *approvals.Event) error) fiber.Handler
- func Auth(client *hibira.Client, ...) fiber.Handler
- func Pass(c fiber.Ctx) *waitingroom.Pass
- func UserAuth(client *hibira.Client, fn func(c fiber.Ctx) *hibira.User) fiber.Handler
- func WaitingRoom(g waitingroom.Guard) fiber.Handler
- func Webhook(client *hibira.Client, fn func(c fiber.Ctx, hook *hibira.Webhook) error) fiber.Handler
Constants ¶
const PassKey = "hibira.pass"
PassKey is the Locals key WaitingRoom stores the visitor's pass under.
Variables ¶
This section is empty.
Functions ¶
func ApprovalCallback ¶
ApprovalCallback receives Approvals decisions sent to a request's callback_url (or a workspace webhook, with its apwh_ secret). secret is the app secret for callback_url deliveries.
func Auth ¶
func Auth(client *hibira.Client, fn func(c fiber.Ctx, channel string) (bool, *hibira.Member)) fiber.Handler
Auth answers pusher-js channel authorization requests. fn decides whether the request's user may subscribe to channel, and for presence- channels returns the member to show.
func Pass ¶
func Pass(c fiber.Ctx) *waitingroom.Pass
Pass returns the waiting room pass WaitingRoom let through, or nil.
func UserAuth ¶
UserAuth answers pusher-js user sign-in requests (pusher.signin()), which the Chat API and server-to-user events need. fn returns the signed-in user, or nil to refuse.
func WaitingRoom ¶
func WaitingRoom(g waitingroom.Guard) fiber.Handler
WaitingRoom lets only visitors with a valid waiting room pass through; others go to the hosted queue page (requests other than GET or HEAD get 403). Read the pass with Pass.
Types ¶
This section is empty.