Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update EventSub Documentation and fix non-existent type #77

Merged
merged 7 commits into from Apr 6, 2021

Conversation

ghostzero
Copy link
Contributor

@ghostzero ghostzero commented Feb 5, 2021

Hey, I have revised the documentation a bit, so that everyone can understand how to use the EventSub.

Also I fixed a type. There had been a typo in it. It should be channel.follow instead of user.follow.

@ghostzero ghostzero force-pushed the eventsub-docs-update branch 6 times, most recently from 6200c68 to 42f7984 Compare February 5, 2021 20:31
src/Enums/EventSubType.php Outdated Show resolved Hide resolved
@ghostzero
Copy link
Contributor Author

I also added a fix for the EventSubSignature class. The timestamp header provided by Twitch has a special date format Y-m-d\TH:i:s.u\Z. I correct this, but cannot validate this with the real api, since Twitch has a Bug. Currently chatting with PooPooKitty from Twitch to verify the right time format.

image

@ghostzero ghostzero marked this pull request as draft February 5, 2021 21:37
@ghostzero
Copy link
Contributor Author

I resolved this. Twitch switched to nanoseconds. Thanks to Dkamps18, he provied a regex for the datetime parser.

@ghostzero ghostzero marked this pull request as ready for review February 6, 2021 13:14
- Fix timestamp format in signature verification
- Deprecate USER_FOLLOW since it's now CHANNEL_FOLLOW.
- Improve documentation
@romanzipp
Copy link
Owner

I don't feel comfortable with that much hacky regex in the getTimestamp method. Could you show an example payload you receive from twitch including the timestamps?

@ghostzero
Copy link
Contributor Author

ghostzero commented Feb 8, 2021

The header looks like this:

{
    "host":["redacted.ngrok.io"],
    "user-agent":["Go-http-client\/1.1"],
    "content-length":["389"],
    "accept-encoding":["gzip"],
    "content-type":["application\/json"],
    "twitch-eventsub-message-id":["6b38997e-eed1-4162-b36f-redacted"],
    "twitch-eventsub-message-retry":["0"],
    "twitch-eventsub-message-signature":["sha256=09803813bd4163ad66e05413c8296d65b3f28ba58b164acc08290eaad57c1ac4"],
    "twitch-eventsub-message-timestamp":["2021-02-05T20:07:58.288209337Z"],
    "twitch-eventsub-message-type":["webhook_callback_verification"],
    "twitch-eventsub-subscription-type":["channel.follow"],
    "twitch-eventsub-subscription-version":["1"],
    "x-forwarded-for":["redacted"],
    "x-forwarded-proto":["https"]
}

@romanzipp
Copy link
Owner

romanzipp commented Feb 9, 2021

Wow this is insane. I don't see any reason whatsoever to use a non-standard date format...

Anyways how about a more flexible expression like /^(?<pre>[\d\-:.T]+)\.(?<nano>\d{6,9})Z$/? (Regex 101 playground)

We would receive the following named matching groups

  "pre" => "2021-02-05T20:07:58"
  "nano" => "288209337"
preg_match('/^(?<pre>[\d\-:.T]+)\.(?<nano>\d{6,9})Z$/', $timestamp, $matches);

Carbon::createFromFormat(
    'Y-m-d\TH:i:s.u\Z',
    sprintf('%s.%dZ', $matches['pre'], substr($matches['nano'], 0, 6))
)

@ghostzero
Copy link
Contributor Author

They use RFC3339Nano in go lang.
This Regex looks more clear 👍

@Xety
Copy link

Xety commented Mar 2, 2021

Any news on this PR ?

@ghostzero
Copy link
Contributor Author

Yes, i updated the regex, as requested. Hope this will be merged soon :)

@ghostzero
Copy link
Contributor Author

I now deploy this branch to Production and subscribe to 2.2 million webhooks. Let's see :D

@romanzipp
Copy link
Owner

Alright, looks good! Could you at least squash the latest commits to remove the merge commit? I'd like to keep the history clean 😄

@ghostzero
Copy link
Contributor Author

@romanzipp can you check it again. 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants