Replies: 13 comments 9 replies
-
|
Does phone-OTP mean sending OTPs through SMS? If so, it's not implemented by default in Keycloak since SMS is inherently insecure (there is no encryption taking place, SIM cards can be stolen through various attack vectors such as user impersonation when interacting with the phone company, and so on) and its use has been discouraged for quite some time. I think that there are some plugins that are publicly available that could take care of sending OTPs through either SMTP or SMS, but I have not tested them myself. Other means of authentication such as OTP applications and various forms of WebAuthn (including passkeys, which can be set up using a phone) are more secure and are supported. |
Beta Was this translation helpful? Give feedback.
-
|
@darius-m, I didn't know that. So, are you telling me that Telegram is insecure for having this type of login? Or is Google insecure for SMSing its OTP as an option? |
Beta Was this translation helpful? Give feedback.
-
|
Of course, you need to consider who your clients are, what attack vectors are possible, what would be the use-case of the application. Sending OTPs through SMS is less secure than OTPs generated locally or WebAuthn, over all, but some applications may not require enforcing such best practices. In some cases it does make sense to provide a solution that trades security for accessibility, such as Google's. Since Google offer their services to masses of users, it does make sense for them to offer SMS as an option, assuming not all users may not have easy access to smartphones, for example. And while I have not verified this, I assume that SMS OTPs have also been implemented for quite some time, and have been kept in place for legacy reasons (among other reasons). Overall, SMS OTPs are better than using single-factor authentication, but I don't think it's something newer applications would normally strive to add. It does make sense to implement in some cases, and that's why Keycloak offers the option to extend its functionality through SPIs. |
Beta Was this translation helpful? Give feedback.
-
|
@darius-m, thank you for the explanation. Are you a member of the Keycloak team? I think just as you mentioned that use cases are different, a built-in SMS OTP provider would be much better than a third-party or homemade SMS OTP provider. At least the guys in Keycloak are masters in security and make it as secure as they can. I searched for third-party plugins, and I found https://github.com/FX-HAO/keycloak-phone-authenticator. The last commit was 3 years ago. That's a big problem right there. You want to help secure the community and you have done a great job. Yet for a small business that wants security and needs to send OTP via SMS to facilitate customer acquisition to reduce marketing costs, it's better to have an out-of-the-box option rather than letting them create it themselves with less security and more costs. Don't you agree? |
Beta Was this translation helpful? Give feedback.
-
|
@darius-m, I found another repository full of examples: https://github.com/thomasdarimont/keycloak-extension-playground Yet again, see the last commit. It was 2 years ago. This, in my opinion, is a higher risk than SMS. A stale codebase is very bad. We have a rule in our team that we update every week, 4 times per month. We constantly apply security patches and keep staying on LTS versions. I don't feel OK for a code that has not been updated for 2 years. |
Beta Was this translation helpful? Give feedback.
This comment was marked as disruptive content.
This comment was marked as disruptive content.
-
|
In my opinion, this discussion should remain open because requests for SMS and Email 2FA/MFA come up quite often, so it's a good idea to centralize and catalog the use cases here. As for the proposition itself, unless you can make a case for it in a non-MFA authentication settingβsuch as the sign-up process some Brazilian banks use, where they rely on SMS and email to confirm ownership before enabling an actual secure authentication method for login, which is usually face biometrics, itβs not a good idea. As Okta states:
Many companies, such as Evernote [06], Twitter [07], and Microsoft [08], are on the path to discontinuing SMS-based 2FA. They recognize that the cost of sending SMS messages and the increased risk of user attacks are not worth the convenience it provides. The same concerns apply to email-based 2FA. Although it is less vulnerable and cheaper than SMS-based methods, it still has the disastrous side effect of enabling a hacker to permanently lock a user out of their account if they gain control of the user's email (personal email, not business email) or clone their SIM card. These are far easier to obtain remotely than if the user relied solely on a username and password, which wouldn't expose them to the risks Okta highlighted (assuming those credentials werenβt leakedβsomething secure 2FA methods were designed to prevent in the first place). Once hackers gain control, they are free to carry out scams on behalf of the user for months, which is particularly common on Instagram [09]. [01] https://www.okta.com/blog/2020/10/sms-authentication/ |
Beta Was this translation helpful? Give feedback.
-
|
@codespearhead, thanks for sharing your thoughts. The point here is not to insist that Phone/OTP is a good or secure method of signing in the users. Nobody insists on that. The points are:
|
Beta Was this translation helpful? Give feedback.
-
|
Hi all, please reply in-thread instead of starting a new thread for every reply. |
Beta Was this translation helpful? Give feedback.
-
|
The Keycloak extensions page lists https://github.com/netzbegruenung/keycloak-mfa-plugins which includes a SMS integration. Note that in 2025, there are several attack vectors to SMS, as https://pages.nist.gov/800-63-3/sp800-63b.html states:
As there are APIs to send SMS, but AFAIK no (common) APIs to receive notifications about device swap, SIM change or number porting, I don't think using SMS is a good idea in 2025. |
Beta Was this translation helpful? Give feedback.
-
|
I have 2 primary use cases which sort of align with this thread, and this seems to be where SMS related questions are being pointed.
I think if there could be a facility for SMS built-in and some enhancements around phone numbers, even if it was non-functional without a provider via a plugin being present (twilio/aws/azure/etc) that may alleviate some of the maintenance burden. That would allow for case 1, and based on risk level someone running keycloak is willing to accept supports case 2. If sponsoring specific features is an option, I think my company may be open to that. If not and there's a vendor with a decent track record of successfully getting features into keycloak via PR I'd appreciate any suggestions. |
Beta Was this translation helpful? Give feedback.
-
|
Phone OTP doesn't need to be SMS where security may be a concern, this is a much needed use case and should be intended to serve as a main authentication flow. One example is WhatsApp authentication, every modern business is supporting authenticating via WhatsApp and KeyCloak is lagging behind. See #37671 |
Beta Was this translation helpful? Give feedback.
-
|
@YandyZaldivar I like your last idea as compromise, but I have a different use case not working. The context would be for an association, where members (not necessarily familiar with computers and security...) needs to authenticate in a simple way (avoid passwords to manage, remember, rotate + having a way to invite them by phone number as primary way). Every year admins can decommission or deactivate accounts. Ideally a WhatsApp/telegram like login would be great. Any idea for something else than SMS ? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Idea
Since phone-OTP login is becoming so widespread, why not have it available out of the box instead of teams spending money and time on it?
Backstory
We chose Keycloak a couple of years ago and everything is awesome now.
Now we want to add phone-OTP to it. Our team is a React/dotnet developer mix; nobody knows Java.
We can't afford to hire a Java developer only to create that phone-OTP plugin.
We tried to outsource it as a project two times and both times we failed. Once they gave us a code written for Keycloak 14 (while we're always updated) and refused to update it, the other did not help us install it and we could not use it at last.
So we decided that maybe we can give it a shot, and we're stuck at building a plugin for it. The reason is that it has its own ecosystem of almost everything, the build tool becomes Maven, the language becomes Java, the IDE of tutorials is not VS Code, and many more differences.
So now we do need this feature, and yet we can't make it work unless we spend more resources than we can afford.
Expected behavior
". There is no validation other than the characters should be numbers or the plus sign.
This is an example of the first form:
This is an example of the second form:
Solution
I guess the phone part is very easy. It's just similar to email.
However, the OTP part is not similar to SMTP configuration, as there are a lot of different SMS providers each with its own API contract.
So, for the second part, I think it could be a very reasonable solution to create a middle API.
In other words, the Keycloak would be configured to send the OTP (or TOTP) to a middle API which we write and pass all the necessary data to that API, and then we can easily call our own SMS providers from that API.
This way all we have to do is to give it a URL and specify an HTTP method (GET or POST, and POST by default).
Some notes
A phone number can be entered in multiple ways. With or without the initial plus sign, with or without spaces, and sometimes with or without the prefix code. And since each means a different user, having a normalization is a MUST. The E.164 standards can be a good standard for this purse. Yet the UX should not be diminished. The user should be able to enter his phone number however he wants, as long as it's valid for sending the code.
The phone/code login is similar to the upsert commands in databases and frameworks. If new records exist, they will be inserted, otherwise, they will be updated. There is no difference in UI and UX between "sign-up" and "sign-in" forms.
Since sending codes through SMS incurs costs, companies might choose to allow phone/password flow too.
Since there are myriads of SMS providers out there, it's impossible for Keycloak to deliver the code. Instead, Keycloak can call an external API that is configured via the admin panel. The call could be a GET or a POST, with two parameters; The phone number, and the code. Example configured URLs could be:
The whole purpose of phone/code login is to simplify entry at the cost of accepting risks. I know Telegram has it because I use it. But if I'm not wrong, Whatsapp, Viber, Uber, TikTok, and some other well-known apps have phone/code login. So adding a captcha anywhere reduces this simplicity and would act counterproductively. However, measures should be taken to prevent brute-force attacks for entering codes.
The length of the code can be configured via the admin panel. The code should be only numeric. No alphabetical characters in the code. Just numbers. And it should be limited to the average memory capacity for human begins (5 to 9 I guess)
Beta Was this translation helpful? Give feedback.
All reactions