Documentation
¶
Overview ¶
Package hibiragin connects Hibira to Gin: channel authorization and user sign-in endpoints for pusher-js, webhook and Approvals callback receivers, and a waiting room middleware. Your functions get the *gin.Context, so whatever your auth middleware stored there is at hand.
client := hibira.FromEnv()
r := gin.Default()
api := r.Group("/hibira", requireLogin)
api.POST("/auth", hibiragin.Auth(client, func(c *gin.Context, channel string) (bool, *hibira.Member) {
u := c.MustGet("user").(*User)
if channel == "private-user-"+u.ID {
return true, nil
}
return strings.HasPrefix(channel, "presence-room-"), &hibira.Member{UserID: u.ID, UserInfo: gin.H{"name": u.Name}}
}))
api.POST("/user-auth", hibiragin.UserAuth(client, func(c *gin.Context) *hibira.User {
return &hibira.User{ID: c.MustGet("user").(*User).ID}
}))
r.POST("/hibira/webhook", hibiragin.Webhook(client, onWebhook))
r.GET("/drop", hibiragin.WaitingRoom(room), dropPage)
Index ¶
- Constants
- func ApprovalCallback(secret string, fn func(c *gin.Context, e *approvals.Event) error) gin.HandlerFunc
- func Auth(client *hibira.Client, ...) gin.HandlerFunc
- func Pass(c *gin.Context) *waitingroom.Pass
- func UserAuth(client *hibira.Client, fn func(c *gin.Context) *hibira.User) gin.HandlerFunc
- func WaitingRoom(g waitingroom.Guard) gin.HandlerFunc
- func Webhook(client *hibira.Client, fn func(c *gin.Context, hook *hibira.Webhook) error) gin.HandlerFunc
Constants ¶
const PassKey = "hibira.pass"
PassKey is the gin.Context key WaitingRoom stores the visitor's pass under.
Variables ¶
This section is empty.
Functions ¶
func ApprovalCallback ¶
func ApprovalCallback(secret string, fn func(c *gin.Context, e *approvals.Event) error) gin.HandlerFunc
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 *gin.Context, channel string) (bool, *hibira.Member)) gin.HandlerFunc
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 *gin.Context) *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) gin.HandlerFunc
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.