# First time login for a user using API KEY

**URL:** https://meta.discourse.org/t/first-time-login-for-a-user-using-api-key/249660
**Category:** SSO
**Tags:** openid-connect, rest-api
**Created:** [December 22, 2022, 11:34am UTC](https://meta.discourse.org/t/first-time-login-for-a-user-using-api-key/249660 "2022-12-22T11:34:09Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![mohit\_kumar](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mohit_kumar/32/284559_2.png) [@mohit\_kumar](https://meta.discourse.org/u/mohit_kumar)
#### Post date: [December 22, 2022, 11:34am UTC](https://meta.discourse.org/t/first-time-login-for-a-user-using-api-key/249660/1 "2022-12-22T11:34:09Z")

</div>

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!!

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [December 22, 2022, 3:29pm UTC](https://meta.discourse.org/t/first-time-login-for-a-user-using-api-key/249660/2 "2022-12-22T15:29:43Z")

</div>

As you suspect, you’ll need to create the user with the API. [Sync DiscourseConnect user data with the sync\_sso route](https://meta.discourse.org/t/sync-discourseconnect-user-data-with-the-sync-sso-route/84398) might help. If not, see [Search results for 'create user api' - Discourse Meta](https://meta.discourse.org/search?q=create%20user%20api), or maybe the good old [Reverse engineer the Discourse API](https://meta.discourse.org/t/reverse-engineer-the-discourse-api/20576)

---

<div class="post-metadata">

### Author: ![mohit\_kumar](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mohit_kumar/32/284559_2.png) [@mohit\_kumar](https://meta.discourse.org/u/mohit_kumar)
#### Post date: [December 23, 2022, 6:16am UTC](https://meta.discourse.org/t/first-time-login-for-a-user-using-api-key/249660/3 "2022-12-23T06:16:40Z")

</div>

[DiscourseConnect](https://meta.discourse.org/t/13045?silent=true) will not work in my case, because at a time either OIDC or [Discourse Connect](https://meta.discourse.org/t/13045?silent=true) can be used. I tried reverse engineering the discourse api.  
The URL is:- [https://smallidea.co/u](https://smallidea.co/u)

It has following payload:-  
{  
name: testuser  
email: [test@xxxxxx.com](mailto: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.
