Iām trying to develop an app that a third party service will send a request to. Iām able to do this, but I have some problems with the authentication process.
Right now when the request is sent the only response that the third party service get is āUser is not currently logged in.ā This must be because the third party service havenāt authenticated itself yet. Manually going to the same route while logged in to nextcloud through an url shows me the response.
Now Iāve tried to send a token (which I get from nc_token cookie) to the third party service, and it uses it as part of its request both in its body (form) and as a authentication header bearer token. This used to work when I was working on this app on nc16, but now on a new server with NC18 it doesnāt work, giving the same error message.
How should I authenticate such a request to nextcloud? Any other apps that does this?
I think your idea lets me access the method, but there is a problem. I donāt want just anyone to access the page, and even if I did, it uses member functions such as getUID, which means making it a public page only returns an error that āMessage: Call to a member function getUID() on nullā.
Any idea how to get around this, or another way to solve this?
When you want to do your own authentication, my understanding is that you need to use a @PublicPage and do authentication yourself. The session manager letās you set a user, for example. So you could verify a token provided as part of the request and set the corresponding user to the session.
Makes sense. I can see that you can set an user with the user session manager, but that requires IUser interface as a parameter and maybe even a login attempt afterward, which I would imagine is hard to do without a password unless token works for passwords. Could you eleborate on how you could do this?
Hi!
Did you get any further in your project? I would like to understand the login-procedure by myself since i want to develop a custom login-service by myself (Custom Login Controller)
in my case the $userSession->login(āusernameā,āpassword") returns true, but nothing happens afterwards. do you know how to actually login (get session-cookies etc.?)
For me it works in a @PublicPage controller with the $this->userSession->login(āusernameā, āpasswordā);
It allowed me to do what I needed to do, but I didnāt actually want to login the user, I just wanted to authenticate the controller. I donāt think it by itself is enough to be logged in. Another project we had where we actually wanted to login a user we had to do something like this: