# יצירת משתמש באופן פרוגרמטי עם מזהה משתמש OAuth2

**URL:** <https://meta.discourse.org/t/programmatically-create-user-with-oauth2-user-id/196920>\
**Category:** Product Support\
**Created:** [12 ביולי,‏ 2021,‏ 11:26pm UTC](https://meta.discourse.org/t/programmatically-create-user-with-oauth2-user-id/196920 "2021-07-12T23:26:39Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![gnuletik](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gnuletik/32/227434_2.png) [@gnuletik](https://meta.discourse.org/u/gnuletik)\
**Post date:** [12 ביולי,‏ 2021,‏ 11:26pm UTC](https://meta.discourse.org/t/programmatically-create-user-with-oauth2-user-id/196920/1 "2021-07-12T23:26:39Z")

</div>

Is there a way to insert a row inside the `user_associated_account` table from the REST API ?

To give you some context, I need to be able to create users on our Discourse instance and link them to our OAuth2 provider.  
When users logs in from the Discourse UI (through OAuth2 Basic Plugin), their account is linked and I can get their discourse user ID from their external UID with `GET /u/by-external/oauth2_basic/{external_uid}`.  
However, when we create users from the REST API (`POST /users.json`), I see no way to link their account to their corresponding OAuth2 account (if they don’t manually log in on Discourse).

FYI, OAuth2 basic plugin implemented the new `Auth::ManagedAuthenticator` system : [https://github.com/discourse/discourse-oauth2-basic/pull/21](https://github.com/discourse/discourse-oauth2-basic/pull/21)

What I tried :

- I looked into the API docs and did not find any clue.
- I found which API route was called to get the associated accounts from one user : `GET /u/{username}/emails.json`. But this route does not seems to support HTTP `PUT` method and does not expose the fields from the `user_associated_accounts` table (`provider_name`, `provider_uid` and `user_id`).
- I also looked into the Discourse settings if anything was related to this issue without any success.
- I checked on [meta.discourse.org](http://meta.discourse.org) and did not found a solution.

Any help is greatly appreciated! Thanks 🙂

---

_[View the full topic](https://meta.discourse.org/t/programmatically-create-user-with-oauth2-user-id/196920)._
