I have a working discourse forum, where users can create a local login (username + password).
I’d like to reuse their login and password in another application. In other words: users would enter their username and password in the other application, and the application should be able to check whether this is a valid login for the forum.
I’ve been reading the documentation for the Discourse API. Many things are possible, including setting username and password for a given user, but I did not find an API endpoint to validate an existing username and password against the list of forum users.
I assume that such an API end point must exist, as the forum must be able to do this to login a user via the web interface.
What is the API end point to check a username and password to login to the forum?
These are suggested methods for authenticating users instead of handling login credentials directly. It also means you don’t need to try to handle 2FA details.
Actually, my “other application” is a desktop app, not a web app. I don’t think discourse-auth-proxy will work in that case.
On the DiscourseConnect page, one of the first statements is this:
Many sites wishing to integrate with a Discourse site want to keep all user registration in a separate site. In such a setup all login operations should be outsourced to that different site.
This is the exact opposite of what I want to do: I want to outsource all login operations to Discourse. Is there a way to use DiscourseConnect to do that?
The tricky thing is that there is a shared secret between the provider (Discourse) and the consumer (your app). If you distribute your app, users will have access to all secrets in it.
Putting auth-proxy in front of a custom minimal web service that gives a signed token to your app might work well.
I’m sure there’s other ways of doing this I’m not thinking of.
Are you referring to the API key? It seems possible to create a “granular” API key, that has access to specific API end points only. It is still not clear to me which endpoints would be required, if I use that approach. Do you know?
Yes, a minimal web service with auth-proxy might be a good solution; I’ll have to experiment a bit to find out.
Not exactly - it would be the discourse connect provider secrets value for the application which would need to be set in conjuction with enable discourse connect provider.
If I understand this correctly, this method would mean that the user logs in using a browser. That can work, although I was hoping to find a method where username and password can be entered in our desktop application, without opening a browser.
I understand that the approach I have in mind will not support TFA unless I implement it myself, and that it will not support logins via third-party providers (Google, Facebook, Discord, …)
As far as I understand at this moment, it looks like the method used in the Reactive Native example can be transposed to our desktop application (which is in Python).
The API access point used seems to be <site>/session, and it takes a username, password and a csrf token. The csrf token can be obtained from <site>/session/csrf.
This is very close to what I was looking for. I think I will try that, will report back if it works for me.
Is the <site>/session API access point documented anywhere?
The best way to what you want in a Desktop app is using User API Keys.
You do need a web interface either in the app or by opening the browser, but if you make your app a handler for the protocol used by the mobile apps, you can easily have it get the token that way and only have to use the browser again if the token expires or they use a different device.
My personal experience with this is that using the User API keys is a much safer and simpler option than trying to use the session end points.
Here are 20 lines of Python code that do approximately the same as the React Native code referred to by @renato (except no compatibiliy with Discourse 2.5 - I don’t need that)
It works well, assuming that you are using basic username-password based login. I will still look into the alternative methods, using the Discourse SSO login as configured in the Discourse instance.
I’ve tried to apply this but can’t get it to work. Below is some (simplified) Python code that generates a url for .../session/sso_provider. When I try it, I get Login Error. No idea what that means.
as admin, enable verbose discourse connect logging, try it, then check /logs on your forum to see more detailed errors, e.g. https://forum.embeetle.com/logs