I think we still have a problem with the token endpoint. I remember discussing it but it never made it into an issue.
We should probably allow posting to the /api/token
endpoint without CSRF, in order to allow apps to create tokens for users without using the /login
endpoint.
I now have created the issue for that flarum/core1905
The only way to do it right now would be to have a script you control to proxy the requests for the token. Send the credentials to that script, have that script check generate the user token via an Api Key, then return the user token. Then the app can use that token to skip CSRF.
The discussion about this was here https://discuss.flarum.org/d/20867-csrf-token-mismatch-on-beta-9-upgrade/8
An alternative would be to fetch the CSRF token for that request (fetch it from a page, then pass it with the first POST request along with the cookies). This should be doable from an application, but that's not super pretty.
Hopefully we can get this fixed in a next beta so it's not as complicated.