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

DEVEXP-201: Verification webhooks #26

Merged
merged 9 commits into from
Dec 12, 2023

Conversation

JPPortier
Copy link
Contributor

@JPPortier JPPortier commented Dec 4, 2023

This PR is adding helpers form SDK for webhooks support to:

  • checkAuthentication: validate authentication has received from request. User do not have to write it own implementation related to hashcode computation/validation
  • unserializeVerificationEvent && serializeVerificationResponse serialize/de-serialize payloads for webhooks callbacks and provide to user ready-to-use classes instance. So do not have to implement it owns outside of SDK
  • a ready to use SpringBoot application as sample for a webhooks backend implementation
  • samples & code cleanup

To provide these helpers, we need to be able to handle both Authentication validation mechanism (Basic and Application) because this setting is managed by user from his dashboard.
So even if we only use Application authentication when SDK is sending request; webhooks validation handle both of them on received requests.

@JPPortier JPPortier changed the title DEEXP-201: Verification webhooks DEVEXP-201: Verification webhooks Dec 4, 2023
Copy link
Contributor

github-actions bot commented Dec 4, 2023

Dependency Review

✅ No vulnerabilities or license issues found.

Snapshot Warnings

⚠️: No snapshots were found for the head SHA b122d13.
Ensure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice.

Scanned Manifest Files

.github/workflows/samples-compilation.yaml
sample-app/pom.xml
  • org.apache.maven.plugins:maven-compiler-plugin@3.8.0

@JPPortier
Copy link
Contributor Author

Please ignore failures for samples
Will fix it, they are due to mix between java used versions but samples are running fine

@JPPortier JPPortier force-pushed the DEVEXP-201-verification-webhooks branch from ce29d56 to 781d129 Compare December 4, 2023 16:30
…hey are store at SinchClient level and a SinchClient instance can handle a single one application (like for single one project id)
README.md Show resolved Hide resolved
Copy link

@650elx 650elx left a comment

Choose a reason for hiding this comment

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

LGTM

* see <a href="https://developers.sinch.com/docs/verification/api-reference/authentication/callback-signed-request">https://developers.sinch.com/docs/verification/api-reference/authentication/callback-signed-request</a>
* @since 1.0
*/
boolean checkAuthentication(

Choose a reason for hiding this comment

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

I'm wondering if it makes sense to have this method in this service, knowing that the voice domain will define the same

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right.
When Voice will arise, it seems refactoring will have sense (something synch with what we have to do related to Application spreading across Voice/Verification)

String[] newSplit = computedAuthorization.split(" ");
String computedHash = newSplit.length > 1 ? newSplit[1] : "";

return computedHash.equals(authorizationHash);

Choose a reason for hiding this comment

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

This function may be refactored to just be about the comparison between the received against the computed value and put the implementation details about how the extract the data in a private function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


Map<String, String> headers =
Stream.of(
new AbstractMap.SimpleEntry<>("authorization", "application foo="),

Choose a reason for hiding this comment

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

Maybe you can test against a value that starts with the application key but with a bad signature only such as 789:foo= so that you are really checking the tampering of the payload

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tests added

@@ -42,7 +41,7 @@ public void resetToken() {

@Override
public Collection<Pair<String, String>> getAuthorizationHeaders(
String method, String httpContentType, String path, String body) {
String timestamp, String method, String httpContentType, String path, String body) {

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks
Fixed

Copy link

@asein-sinch asein-sinch left a comment

Choose a reason for hiding this comment

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

Very nice ⭐️

@JPPortier JPPortier merged commit 0b791b3 into feat/verification Dec 12, 2023
2 checks passed
@JPPortier JPPortier deleted the DEVEXP-201-verification-webhooks branch December 12, 2023 07:15
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.

3 participants