How can an API user create posts as another user?

I’m using the API of Discourse with a custom UI. I’m attempting to integrate this behind an orchestration layer that already authenticates users. I’d like to be able to more or less bypass authentication on the Discourse side of things.

We use JWT tokens, and it seems that ideally I could just pass these along to Discourse and tell it to trust them. I see that there’s some JWT related projects in the discourse GitHub organization, but there’s no documentation or usage examples, Google hasn’t been helpful, I haven’t found any relevant threads in meta, and I don’t really speak Ruby :frowning:

Is there a way I could leverage our existing authentication by just passing these tokens through to Discourse?

Failing that, as an API user, how can I create topics and posts on behalf of other, authenticated users?

One strategy I’m exploring is creating an API user for every user in my system. Any obvious downsides to this?

You could use a master API key, and specify the username of the user you are impersonating – the master API key should always work.

Okay, that’s interesting. How would you specify the user name? As the api_username parameter on the query string?

Yes, exactly. This is the name of the user performing the action, while the API key just proves you’re allowed to speak for that user.

Excellent, that sounds perfect. I’ll try it out.

I’m trying to do this, but I cannot specify an arbitrary username as api_username - if I specify any username other than my (admin) account, I get a 404 from the API.

Is this post out of date, or is there some other way to achieve creating topics as another user (other than creating an API key for every user)?

Penso che l’API sia cambiata da quando è stato creato il post. Oggi è necessario specificare il nome utente tramite l’intestazione HTTP Api-Username:…

Ciao a tutti,

Scrivo perché sto cercando di popolare il mio forum con post creati da un gruppo di utenti provenienti da un altro vecchio forum.

Nella documentazione è spiegato come creare un post tramite l’API, ma non sono sicuro di come fare in modo che questi post appaiano come provenienti da un utente specifico. La soluzione proposta in precedenza sembra non funzionare più.

C’è un campo in cui potrei inserire il nome utente? Non riesco a trovarlo nella documentazione.

Grazie per il vostro aiuto!

Hai mai pensato di provare uno script di migrazione?

Potrebbe essere molto più semplice. Inoltre, su Meta ci sono molti tutorial passo passo, a seconda della piattaforma su cui gira il vecchio forum.

Se crei una chiave API per “Tutti gli utenti”:

Puoi quindi specificare il nome utente per cui desideri creare i post tramite l’intestazione Api-Username quando effettui la richiesta API.

Grazie @blake, penso che seguirò quella strada.
@justin, grazie, per il momento preferisco attenermi alle API, ma terrò presente l’importatore per il futuro!