diff --git a/cmd/events.go b/cmd/events.go index 0217a1f1..35ca5cd9 100644 --- a/cmd/events.go +++ b/cmd/events.go @@ -176,6 +176,7 @@ func init() { verifyCmd.Flags().StringVar(×tamp, "timestamp", "", "Sets the timestamp to be used in payloads and headers. Must be in RFC3339Nano format.") verifyCmd.Flags().StringVarP(&eventID, "subscription-id", "u", "", "Manually set the subscription/event ID of the event itself.") // TODO: This description will need to change with https://github.com/twitchdev/twitch-cli/issues/184 verifyCmd.Flags().StringVarP(&version, "version", "v", "", "Chooses the EventSub version used for a specific event. Not required for most events.") + verifyCmd.Flags().StringVarP(&toUser, "broadcaster", "b", "", "User ID of the broadcaster for the verification event.") verifyCmd.MarkFlagRequired("forward-address") // websocket flags @@ -313,12 +314,13 @@ https://dev.twitch.tv/docs/eventsub/handling-webhook-events#processing-an-event` } _, err := verify.VerifyWebhookSubscription(verify.VerifyParameters{ - Event: args[0], - Transport: transport, - ForwardAddress: forwardAddress, - Secret: secret, - Timestamp: timestamp, - EventID: eventID, + Event: args[0], + Transport: transport, + ForwardAddress: forwardAddress, + Secret: secret, + Timestamp: timestamp, + EventID: eventID, + BroadcasterUserID: toUser, Version: version, }) diff --git a/docs/event.md b/docs/event.md index 828dfbf3..cd3eade7 100644 --- a/docs/event.md +++ b/docs/event.md @@ -5,7 +5,7 @@ - [Trigger](#trigger) - [Retrigger](#retrigger) - [Verify-Subscription](#verify-subscription) - - [Websocket](#websocket) + - [WebSocket](#websocket) ## Description @@ -154,6 +154,7 @@ This command takes the same arguments as [Trigger](#trigger). | Flag | Shorthand | Description | Example | Required? (Y/N) | |---------------------|-----------|----------------------------------------------------------------------------------------------------------------------|-----------------------------|-----------------| +| `--broadcaster` | `-b` | The broadcaster's user ID to be used for verification | `-b 1234` | N | | `--forward-address` | `-F` | Web server address for where to send mock subscription. | `-F https://localhost:8080` | Y | | `--secret` | `-s` | Webhook secret. If defined, signs all forwarded events with the SHA256 HMAC and must be 10-100 characters in length. | `-s testsecret` | N | | `--transport` | `-T` | The method used to send events. Default is `eventsub`. | `-T eventsub` | N | diff --git a/internal/events/verify/subscription_verify.go b/internal/events/verify/subscription_verify.go index 11b21b8c..647bd8ff 100644 --- a/internal/events/verify/subscription_verify.go +++ b/internal/events/verify/subscription_verify.go @@ -19,13 +19,14 @@ import ( ) type VerifyParameters struct { - Transport string - Timestamp string - Event string - ForwardAddress string - Secret string - EventID string - Version string + Transport string + Timestamp string + Event string + ForwardAddress string + Secret string + EventID string + Version string + BroadcasterUserID string } type VerifyResponse struct { @@ -55,7 +56,11 @@ func VerifyWebhookSubscription(p VerifyParameters) (VerifyResponse, error) { p.EventID = util.RandomGUID() } - body, err := generateWebhookSubscriptionBody(p.Transport, p.EventID, event.GetTopic(p.Transport, p.Event), event.SubscriptionVersion(), challenge, p.ForwardAddress) + if p.BroadcasterUserID == "" { + p.BroadcasterUserID = util.RandomUserID() + } + + body, err := generateWebhookSubscriptionBody(p.Transport, p.EventID, event.GetTopic(p.Transport, p.Event), event.SubscriptionVersion(), p.BroadcasterUserID, challenge, p.ForwardAddress) if err != nil { return VerifyResponse{}, err } @@ -133,7 +138,7 @@ func VerifyWebhookSubscription(p VerifyParameters) (VerifyResponse, error) { return r, nil } -func generateWebhookSubscriptionBody(transport string, eventID string, event string, subscriptionVersion string, challenge string, callback string) (trigger.TriggerResponse, error) { +func generateWebhookSubscriptionBody(transport string, eventID string, event string, subscriptionVersion string, broadcaster string, challenge string, callback string) (trigger.TriggerResponse, error) { var res []byte var err error ts := util.GetTimestamp().Format(time.RFC3339Nano) @@ -147,7 +152,7 @@ func generateWebhookSubscriptionBody(transport string, eventID string, event str Type: event, Version: subscriptionVersion, Condition: models.EventsubCondition{ - BroadcasterUserID: util.RandomUserID(), + BroadcasterUserID: broadcaster, }, Transport: models.EventsubTransport{ Method: "webhook",