First time login for a user using API KEY

Hi All,

I am using Discourse as a backend only there is no discourse UI involvement. To use API, I am using username and global api key to hit the request.
I am facing 1 problem that is whenever a new user is created in my OIDC provider(Keycloak), I just cannot use it’s username in my API. Discourse is not recognising the user.
I tried to debug this and realized that discourse also creates a user when a user successfully login from OIDC for the first time and it shows banner on UI that account successfully created. After this only I can use the username to hit the API.
I want to automate this flow without need of UI. Basically I mean, If a user is created in my OIDC platform then without using UI, I should be able to use it’s username and global api key to hit my request. I am open for hitting additional API.

Any leads will be helpful.
Thanks in Advance!!

As you suspect, you’ll need to create the user with the API. Sync DiscourseConnect user data with the sync_sso route might help. If not, see Search results for 'create user api' - Discourse Meta, or maybe the good old Reverse engineer the Discourse API

3 Likes

DiscourseConnect will not work in my case, because at a time either OIDC or Discourse Connect can be used. I tried reverse engineering the discourse api.
The URL is:- Genius

It has following payload:-
{
name: testuser
email: test@xxxxxx.com
username:discoursetestuser3
password_confirmation:2290e67e2f59d6b9a0edbc735cef0e1d
challenge:598d41761746371257a4c89d5ac61260
timezone:Asia/Calcutta
}

I am not able to understand “password_confirmation” and “challenge” parameters. Any idea what is this ?
Both of these parameters are dynamic and there is no fixed value that I can pass. This is random.