-
Notifications
You must be signed in to change notification settings - Fork 416
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
Add custom sms provider #558
Conversation
Hey @mamousavi, Thanks for the PR! Let us know if you need any help with this Joel |
Hey @J0, |
@mamousavi thanks for the PR! Unfortunately, this wouldn't work because other SMS providers might have different API specifications for sending SMSes. Take Vonage for example, it requires the ApiKey and ApiSecret. |
@kangmingtay that's exactly right, hence the name "custom". Ideally users need to wrap their preferred provider in their own endpoint. |
@kangmingtay The default providers are not affordable for many developers in some countries. Plus Auth0 supports using a custom sms gateway which this PR was inspired by. |
Hey @mamousavi, this is a great PR! We've been thinking about adding more general webhook capabilities to GoTrue, and this is a good first start. Would you mind using terms like For example, call the env. vars. something like {
[header: string]: string | string[]
} So in your case, adding the Authorization header would look like: {
"Authorization": "Bearer <...>"
} One really important piece that is missing from this is a way to authenticate GoTrue at the receiving service. Typically this is done by exchanging some sort of secret where GoTrue computes an HMAC value and adds it to the headers of the request. A good approach is Stripe's. Also, we really appreciate tests so if you could add them that would be splendid! |
Hey @hf thanks for the comment. |
@hf In the current approach, the gateway is not supposed to be a webhook endpoint in the first place. Users might want to use the same gateway in their own microservices. There's no need for gotrue to sign the requests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add tests for your custom provider!
api/sms_provider/custom.go
Outdated
body, err := json.Marshal(map[string]string{ | ||
"recipient": phone, | ||
"body": message, | ||
"sender": t.Config.Sender, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
client := &http.Client{Timeout: defaultTimeout} | ||
r, err := http.NewRequest("POST", t.Config.Url, bytes.NewBuffer(body)) | ||
if err != nil { | ||
return err | ||
} | ||
r.Header.Add("Content-Type", "application/json") | ||
if len(t.Config.BearerToken) > 0 { | ||
r.Header.Add("Authorization", "Bearer "+t.Config.BearerToken) | ||
} | ||
res, err := client.Do(r) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if res.StatusCode/100 != 2 { | ||
return fmt.Errorf("Unexpected response while calling the SMS gateway: %v", res.StatusCode) | ||
} | ||
|
||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest using a more generic approach here as mentioned in one of the previous comments. Instead of specifying an Authorization
header specifically, it is better and more flexible in my opinion to set any headers that you may need -- like API keys or other special values.
Furthermore, I don't see the need for the "sender"
field. You only need to post the message and recipient phone number.
Finally, please handle HTTP errors and redirects correctly. For example, if the URL returns a 301 response, what happens? What's the timeout?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just followed the guide from Auth0 which covers most use cases. It's not a matter of opinion; It's best we KISS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally, please handle HTTP errors and redirects correctly. For example, if the URL returns a 301 response, what happens? What's the timeout?
It returns an error for any non-2xx response similar to the twilio provider. Also it uses the predefined timeout similar to all external providers.
example.env
Outdated
GOTRUE_SMS_CUSTOM_SENDER="" | ||
GOTRUE_SMS_CUSTOM_BEARER_TOKEN="" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SENDER
is not necessary IMO, while the BEARER_TOKEN
should be replaced with a JSON-like map that sets various headers on the request (not just Authorization).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know SENDER
is not necessary but supplying it aligns better with other provider configurations.
I can't find any sms provider tests for reference. |
any updates? |
@mamousavi @hf will this PR be merged and released any time soon? |
I am willing to take care if this. I need this very urgently and I kinda don't want to maintain a fork. |
any updates? i reaaaaaaaaaaaally need this asap! and just like @rokk4 it will be tedious to maintain a fork, also i want to use the supabase platform instead of hosting said fork myself. Thanks to all the maintainers, all of your efforts are appreciated. 🤝 |
Hey @abdirahmn1 and team, Thanks for patiently waiting and for taking the time to put together this PR. I'm really sorry to be the bearer of bad news but we're unlikely going to move forward with this PR as we'll be pursuing a hook based approach. The hope is that there'll be more room for flexibility in terms of SMS (e.g. dynamically select senders) with the hook since developers can modify code within the hook. Custom SMS Providers is on the top of our priority list and discussion is underway. We'll have more updates to share soon. In the meantime, please let us know if there are any questions or concerns. Thanks! |
Thanks @J0 for taking the time, is there a timeline for when this feature will be published?, if not, can you please give me a rough estimate and your opinion of when you think it might be available. Take care and stay safe 😊. |
Hi, when will these feature be merged ? |
We aim to merge support before the end of March, likely sooner. Going to close for now Let us know if there are further concerns. Thanks everyone for the contribution! |
@J0 March has ended. What's the update? |
Ah thanks for patiently waiting. We’ve merged support in #1474 . Docs will follow within the next 2 weeks |
Why can't I still see the option to choose custom SMS provider on Supabase Auth Providers? |
What kind of change does this PR introduce?
Add support for using a custom SMS gateway to send out OTPs.
What is the current behavior?
Does not support custom gateways.
What is the new behavior?
By changing the following env variables, users will be able to send out OTPs through a custom SMS gateway:
Implementation will send the following to the SMS gateway:
Implementation will only consider the HTTP code returned from the SMS gateway; it ignores the rest of the response (e.g., response body and response type).
Additional context