Iām developing a site where users must be able to log to their Nextcloud account. The 2FA is enabled by default by the administrator of the Nextcloud. I donāt really understand how I can use the API with the 2fa.
Maybe not⦠may be this even not a good way for your problem. As long you donāt show what you are doing and what is the problem itās hard to find right solition.
I have a site like āexemple.comā, that needs to connect with a Nextcloud server. The users will never connect to the Nextcloud server, only on the site.
Once on the site, the users need to enter their Nextcloud login information. Then, they will have the list of their files, they can download them and upload a new file.
the intention if 2FA is exactly how it works - additional secret must be provided together with userid and password. you are asking to break 2FA. You application acts āon behalfā the user. curl command is nothing else as āanother browserā and needs to provide second factor for successful authentication. There are scenarios when legacy clients do not support modern auth (e.g. WebDAV) - this where you can create fake user/password combination and access the system using single factor auth.
BTW: I donāt really get the goal of your application⦠You can limit the user right to files app only and have native interface to up/download files⦠or access the files using WebDAV which is integral part of the system.
BTW: I donāt really get the goal of your application⦠You can limit the user right to files app only and have native interface to up/download files⦠or access the files using WebDAV which is integral part of the system.
Sure, however the final client wants to have his own site and design, he doesnāt want his users to have access directly to the Nextcloud (theyāre even on separate web hosting). I was asked to just develop the link between the Nextcloud and the site. The decision and user management is not within my control.
I think your client does not really understand what they are asking for.
Accessing 2FA service without 2FA is a nonsense (while spending money on additional development) ⦠Additionally from a security point of view - dealing with clear text credentials of a 3rd-party service?!.. never.ever!!! you are in trouble if you do this. no way to winā¦
If you are serious developer stop here, discuss the requirements with your client and ask for serious and useful order.
You need to redirect your users to log in through the nextcloud login flow (Login Flow ā Nextcloud latest Developer Manual latest documentation) instead of entering the credentials on the site directly. There is no getting around registering a session on the Nextcloud side, that gives you credentials to use in your application.
You should not think of the application as an alternative frontend for the Nextcloud, as that means you need to reimplement A LOT of stuff to make it interact with the Nextcloud backend, like the normal frontend does. Instead think of it like a Nextcloud client, like the mobile clients: They are essentially different frontends to the nextcloud functionality, but they do not re-implement the complex nextcloud frontend login logic influenced by many server apps and instead open it in a webview.
Thank you, @TessyPowder, for your answer, that finally confirm what I already suspect. Now I can work with that and stop looking for a potential alternative;)
Second factor methods are provided by apps and AFAIK they only return the html code to be shown in the frontend when the second factor is entered and a method for the nextcloud server backend to validate it. The implementation is tied to the nextcloud frontend. I am not aware of any clean API, only html endpoints containing <a>s and <form>s that make it work. That is implemented here: server/TwoFactorChallengeController.php at master Ā· nextcloud/server Ā· GitHub
Other than parsing frontend html and using that an āAPIā, which you probably donāt want to do I see no other way than the login flow, but maybe somebody else knows more than me.