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

feat: added sms support to courier #1941

Merged
merged 10 commits into from
Feb 23, 2022
Merged

Conversation

oleksiireshetnik
Copy link
Contributor

@oleksiireshetnik oleksiireshetnik commented Nov 9, 2021

Related issue(s)

Checklist

  • I have read the contributing guidelines.
  • I have referenced an issue containing the design document if my change
    introduces a new feature.
  • I am following the
    contributing code guidelines.
  • I have read the security policy.
  • I confirm that this pull request does not address a security
    vulnerability. If this pull request addresses a security. vulnerability, I
    confirm that I got green light (please contact
    security@ory.sh) from the maintainers to push
    the changes.
  • I have added tests that prove my fix is effective or that my feature
    works.
  • I have added or changed the documentation.

Further Comments

@oleksiireshetnik
Copy link
Contributor Author

oleksiireshetnik commented Nov 9, 2021

I try to be as close as possible to Twillio API contract for sending sms.
Also, I split SMTP and SMS logic into different files, but tried to preserve initial courier responsibility - to pull messages from database and send them regardless of type.

Also I tested this PR and #1938 in local setup, it works fine.

@oleksiireshetnik oleksiireshetnik changed the title Added sms support to courier feat: added sms support to courier Nov 9, 2021
Copy link
Member

@aeneasr aeneasr left a comment

Choose a reason for hiding this comment

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

Hey, this looks awesome! We would need some docs for this as well: https://www.ory.sh/kratos/docs/concepts/email-sms#sending-sms

Once you mark it for ready for review, I'll finalize the review :)

@oleksiireshetnik
Copy link
Contributor Author

Added documentation for sending SMS using courier

Copy link
Member

@aeneasr aeneasr left a comment

Choose a reason for hiding this comment

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

Thank you, this is looking grand! :)

Since I forgot to mention this in the other PR. Could you please add to the documentation how to use phone numbers as part of the identity traits over at

Thank you :)

courier/template/sms_login.go Outdated Show resolved Hide resolved
courier/template/sms_login.go Outdated Show resolved Hide resolved
courier/template/sms_login.go Outdated Show resolved Hide resolved
courier/template/sms_stub.go Outdated Show resolved Hide resolved
courier/template/sms_stub.go Outdated Show resolved Hide resolved
courier/sms.go Outdated Show resolved Hide resolved
courier/dispatcher.go Outdated Show resolved Hide resolved
courier/courier_test.go Outdated Show resolved Hide resolved
courier/courier_test.go Outdated Show resolved Hide resolved
courier/sms.go Show resolved Hide resolved
@aeneasr
Copy link
Member

aeneasr commented Dec 29, 2021

Regarding the SMS sending logic, I think you could probably reuse the logic we have for the web hooks! Those allow you to:

  1. Set custom auth
  2. Set the HTTP body payload (as json)
  3. Set the HTTP method
  4. Set the HTTP URL

This could allow us to integrate with a lot of providers such as twilio and others out of the box :)

@aeneasr
Copy link
Member

aeneasr commented Dec 29, 2021

Once you need another review, just re-request review from me :)

@splaunov
Copy link
Contributor

@alexey-reshetnik just to let you know. The code updates message status twice. The second time generating an error.
Fixed in this commit:
monta-app@6590f0a

@oleksiireshetnik
Copy link
Contributor Author

@splaunov thank you. Included fix in the commit

@oleksiireshetnik
Copy link
Contributor Author

oleksiireshetnik commented Jan 26, 2022

@aeneasr added JsonNet support for making requests from the courier. Moved request forming logic to separate package, and added additional functionality to it:

  • setting custom headers
  • support for urlencoded content-type

Now it must be configurable with most SMS providers

@oleksiireshetnik oleksiireshetnik force-pushed the courier-sms branch 2 times, most recently from 8684de0 to 9d239d4 Compare January 26, 2022 19:12
@aeneasr aeneasr reopened this Feb 14, 2022
@aeneasr aeneasr changed the base branch from v0.8 to master February 14, 2022 18:48
@oleksiireshetnik
Copy link
Contributor Author

oleksiireshetnik commented Feb 16, 2022

Hi @Benehiko
All your comments make sense, thanks. Fixed them, adding documentation now

@codecov
Copy link

codecov bot commented Feb 16, 2022

Codecov Report

Merging #1941 (f62f33c) into master (c5a04b5) will decrease coverage by 0.03%.
The diff coverage is 79.92%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1941      +/-   ##
==========================================
- Coverage   75.88%   75.85%   -0.04%     
==========================================
  Files         298      308      +10     
  Lines       15917    16111     +194     
==========================================
+ Hits        12079    12221     +142     
- Misses       2979     3012      +33     
- Partials      859      878      +19     
Impacted Files Coverage Δ
courier/message.go 100.00% <ø> (ø)
courier/sms.go 60.37% <60.37%> (ø)
courier/sms_templates.go 63.63% <63.63%> (ø)
courier/courier_dispatcher.go 64.28% <64.28%> (ø)
driver/config/config.go 81.51% <66.66%> (-0.39%) ⬇️
selfservice/strategy/link/sender.go 71.27% <66.66%> (ø)
courier/smtp.go 74.00% <74.00%> (ø)
request/builder.go 77.77% <77.77%> (ø)
request/auth.go 80.00% <80.00%> (ø)
courier/template/testhelpers/testhelpers.go 95.06% <83.33%> (ø)
... and 15 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c5a04b5...f62f33c. Read the comment docs.

@oleksiireshetnik
Copy link
Contributor Author

Added documentation: ory/docs#601

Copy link
Contributor

@Benehiko Benehiko left a comment

Choose a reason for hiding this comment

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

Nice job! This looks really good :)

I just have one last request, we just need some failure cases for the schema fixtures then this would be good to go IMO :)

embedx/config.schema.json Show resolved Hide resolved
Comment on lines +1 to +23
selfservice:
default_browser_return_url: "#/definitions/defaultReturnTo"

dsn: foo

identity:
schemas:
- id: default
url: https://example.com

courier:
smtp:
connection_uri: smtps://foo:bar@my-mailserver:1234/
from_address: no-reply@ory.kratos.sh
sms:
enabled: true
from: "+19592155527"
request_config:
url: https://sms.example.com
method: POST
body: file://request.config.twilio.jsonnet
header:
'Content-Type': "application/x-www-form-urlencoded"
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

@aeneasr
Copy link
Member

aeneasr commented Feb 16, 2022

Shall I take a look also soon? Or do you want to address more things first?

@Benehiko
Copy link
Contributor

Shall I take a look also soon? Or do you want to address more things first?

You can take a look :)
I'm satisfied with the PR (just need the schema fixtures for failures).

Copy link
Contributor

@Benehiko Benehiko left a comment

Choose a reason for hiding this comment

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

From my side, this looks good :)

embedx/config.schema.json Show resolved Hide resolved
Copy link
Member

@aeneasr aeneasr left a comment

Choose a reason for hiding this comment

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

Thank you to everyone involved, this looks fantastic. I have added a few things and also ensured that SSRF can't happen if configured. I left a few comments for some easy-to-add tests but otherwise this is good to ship!

request/builder.go Show resolved Hide resolved
embedx/config.schema.json Show resolved Hide resolved
embedx/config.schema.json Show resolved Hide resolved
embedx/config.schema.json Show resolved Hide resolved
driver/config/config.go Show resolved Hide resolved
courier/sms.go Show resolved Hide resolved
courier/sms.go Outdated Show resolved Hide resolved
@aeneasr

This comment was marked as resolved.

@aeneasr aeneasr merged commit 8c58e94 into ory:master Feb 23, 2022
@oleksiireshetnik oleksiireshetnik deleted the courier-sms branch February 23, 2022 14:38
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

5 participants