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

[MAP-24] Add Golang webhook server example #63

Merged
merged 9 commits into from
Apr 14, 2022

Conversation

tl-marco-tormento
Copy link
Contributor

@tl-marco-tormento tl-marco-tormento commented Apr 13, 2022

#47 for Golang, including jwks fetch caching.

Golang webhook server example

A http server than can receive and verify signed TrueLayer webhooks.

Run

Run the server.

go run main.go

Send a valid webhook that was signed for path /hook/d7a2c49d-110a-4ed2-a07d-8fdb3ea6424b.

curl -iX POST -H "Content-Type: application/json" \
    -H "X-Tl-Webhook-Timestamp: 2022-03-11T14:00:33Z" \
    -H "Tl-Signature: eyJhbGciOiJFUzUxMiIsImtpZCI6IjFmYzBlNTlmLWIzMzUtNDdjYS05OWE5LTczNzQ5NTc1NmE1OCIsInRsX3ZlcnNpb24iOiIyIiwidGxfaGVhZGVycyI6IngtdGwtd2ViaG9vay10aW1lc3RhbXAiLCJqa3UiOiJodHRwczovL3dlYmhvb2tzLnRydWVsYXllci5jb20vLndlbGwta25vd24vandrcyJ9..AE_QsBRhnsMkcRzd42wvY1e2HruUhkOgjuZKktGH_WmbD7rBzoaEHUuF36IxyyvCbLajd3MBExNmzjbrOQsGaspwAI5DcGVMFLKUhB7ZzUlTP9up3eNUrdwWyyfBWDQb-qmEuLnrhFDJvgCXEqlV5OLrt-O7LaRAJ4f9KHsZLQ_j2vPC" \
    -d "{\"event_type\":\"payout_settled\",\"event_schema_version\":1,\"event_id\":\"8fb9fb4e-bb2b-400b-af64-59e5dde74bad\",\"event_body\":{\"transaction_id\":\"c34c8721-66a9-49f6-a229-284efcf88a02\",\"settled_at\":\"2022-03-11T14:00:32.933000Z\"}}" \
    http://localhost:7000/hook/d7a2c49d-110a-4ed2-a07d-8fdb3ea6424b

Modifying the X-Tl-Webhook-Timestamp header, the body or the path will cause the above signature to be invalid.

@tl-marco-tormento tl-marco-tormento requested a review from a team as a code owner April 13, 2022 17:07
@tl-marco-tormento tl-marco-tormento requested a review from a team April 13, 2022 17:07
@tl-marco-tormento tl-marco-tormento marked this pull request as draft April 13, 2022 17:07

require (
github.com/Truelayer/truelayer-signing/go v0.1.4 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If anyone knows about a better http cache...
This is not actively maintained but it does the job.

@tl-marco-tormento tl-marco-tormento marked this pull request as ready for review April 14, 2022 08:49
@alexheretic
Copy link
Contributor

Where's the readme?

Actually related to that, you should also add links to the main go README too, like

Copy link
Contributor

@tl-flavio-barinas tl-flavio-barinas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just a couple of questions.

go/examples/webhook-server/main.go Outdated Show resolved Hide resolved
Copy link

@onatm onatm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! I've just made a couple of suggestions.

go/examples/webhook-server/main.go Show resolved Hide resolved
go/examples/webhook-server/main.go Show resolved Hide resolved
go/examples/webhook-server/main.go Outdated Show resolved Hide resolved
@tl-marco-tormento tl-marco-tormento merged commit 3a5d70e into main Apr 14, 2022
@tl-marco-tormento tl-marco-tormento deleted the golang-webhook-example-server branch April 14, 2022 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants