# "Fake" OAuth Provider?

**URL:** https://meta.discourse.org/t/fake-oauth-provider/212116
**Category:** Development
**Created:** [December 14, 2021, 10:57pm UTC](https://meta.discourse.org/t/fake-oauth-provider/212116 "2021-12-14T22:57:27Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![cookieman768](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cookieman768/32/118511_2.png) [@cookieman768](https://meta.discourse.org/u/cookieman768)
#### Post date: [December 14, 2021, 10:57pm UTC](https://meta.discourse.org/t/fake-oauth-provider/212116/1 "2021-12-14T22:57:27Z")

</div>

Hello 👋 I’m wondering if something I’m trying to do would even be possible.

So, I’m wanting to associate Minecraft accounts with Discourse Accounts much like how you can add Discord, Google, etc. but, Minecraft doesn’t have an OAuth system currently (maybe once everyone is migrated to a Microsoft account but, that’d be a bit of waiting). So, the system I am proposing is having the user enter a randomly generated code that they’d get in-game. Would there be a way to then add this to their account like any other connected account? I’d probably structure it similar to how [https://mc-oauth.net/](https://mc-oauth.net/) works but, instead of logging in, they’d use a command in chat.

If this _would_ be possible, do you have any pointers on how I could accomplish this? I pretty much just would need a modal popup asking for the code → validate code → get UUID and store as external account identifier.

EDIT: Actually, it looks like with the transition to Microsoft accounts I _might_ be able to modify the existing Microsoft account plugin to store Minecraft UUIDs. I’ll have to see.

---

<div class="post-metadata">

### Author: ![awesomerobot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/awesomerobot/32/142900_2.png) [@awesomerobot](https://meta.discourse.org/u/awesomerobot)
#### Post date: [December 15, 2021, 6:22pm UTC](https://meta.discourse.org/t/fake-oauth-provider/212116/2 "2021-12-15T18:22:54Z")

</div>

You could maybe use custom user fields for this? [Creating and configuring custom user fields](https://meta.discourse.org/t/how-to-create-and-configure-custom-user-fields/113192)

A user field could be set to be required on signup, which would accept the randomly generated code. User fields can also be editable in someone’s preferences after signup, if existing accounts need to add the code.

---

<div class="post-metadata">

### Author: ![cookieman768](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cookieman768/32/118511_2.png) [@cookieman768](https://meta.discourse.org/u/cookieman768)
#### Post date: [December 15, 2021, 8:44pm UTC](https://meta.discourse.org/t/fake-oauth-provider/212116/3 "2021-12-15T20:44:50Z")

</div>

Oooooh, I actually didn’t think about this. Thank you for the idea - the main reason why I was looking for an OAuth approach is I can retrieve the user by the external ID. I’m going to see if I could potentially retrieve a user by a user field.

EDIT: Ok, I actually might have a way of doing this using the custom fields. I’m probably going to just have to use an external database and make my own way of requesting a Discourse user from their Minecraft UUID. I just don’t know enough about the limitations of Discourse to know if there’d be a better way.

EDIT 2: Hmm, I don’t see a way to edit custom user fields via the API. I ideally wanted to have it only get set by the API, so it is guaranteed that they own the account. I might just need to make an external database and do account linking through something else.

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [December 15, 2021, 11:32pm UTC](https://meta.discourse.org/t/fake-oauth-provider/212116/4 "2021-12-15T23:32:48Z")

</div>

It kind of sounds like what you want to do is implement your own oauth provider?

Much like the [diagram here](https://meta.discourse.org/t/overview-single-sign-on-sso-oauth2-is-this-chart-correct/90231/2):

 ![image](https://global.discourse-cdn.com/meta/original/3X/4/c/4c6f513ef8b58ae711c4ba3adc0f13c9ce0b68ef.png)

It sounds like your custom mechanism would take the place of the “oAuth2 Directory”.

(It might be simpler using [DiscourseConnect](https://meta.discourse.org/t/13045?silent=true))

Of course, this all depends on how you’re already implementing authentication for the site…

On the other hand, doing that might be overcomplicating things — we do support staff-only custom fields that might be suitable here.

---

<div class="post-metadata">

### Author: ![cookieman768](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cookieman768/32/118511_2.png) [@cookieman768](https://meta.discourse.org/u/cookieman768)
#### Post date: [December 16, 2021, 2:03am UTC](https://meta.discourse.org/t/fake-oauth-provider/212116/5 "2021-12-16T02:03:17Z")

</div>

Yeah, I guess my only main question is if it were staff-only would there be a way to set those fields via some API route? I couldn’t find a way to do so automatically.

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [December 16, 2021, 3:16am UTC](https://meta.discourse.org/t/fake-oauth-provider/212116/6 "2021-12-16T03:16:41Z")

</div>

> [@cookieman768](#):
>
> would there be a way to set those fields via some API route

I don’t see an entry in [docs.discourse.org](http://docs.discourse.org) for this one. All changes made by the web browser are done using the same API, so my advice would be to [reverse engineer what’s needed](https://meta.discourse.org/t/how-to-reverse-engineer-the-discourse-api/20576).

---

<div class="post-metadata">

### Author: ![cookieman768](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cookieman768/32/118511_2.png) [@cookieman768](https://meta.discourse.org/u/cookieman768)
#### Post date: [December 16, 2021, 4:35pm UTC](https://meta.discourse.org/t/fake-oauth-provider/212116/7 "2021-12-16T16:35:22Z")

</div>

Oh, that’s really useful - thank you for sharing! So, I did some more thinking and research on _how_ I could do this, what I’m thinking is using the `state` parameter with OAuth to have people sign in to their Discourse account and then use that state to associate the UUID in Minecraft. The state would just be some randomly generated value that would exist in a database with the Minecraft UUID. I think this approach _should_ work. Thank you everyone for all the ideas and resources!

---

<div class="post-metadata">

### Author: ![cookieman768](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cookieman768/32/118511_2.png) [@cookieman768](https://meta.discourse.org/u/cookieman768)
#### Post date: [January 26, 2022, 5:14am UTC](https://meta.discourse.org/t/fake-oauth-provider/212116/8 "2022-01-26T05:14:23Z")

</div>

Since I didn’t need access to the Minecraft UUID from within Discourse itself, I ended up making an external system that integrates with [Discourse SSO](https://meta.discourse.org/t/13045?silent=true). I appreciate the help, and if you’d like to see what I came up with, I shared it [here](https://meta.discourse.org/t/using-discourse-as-an-identity-provider-sso-discourseconnect/32974/127). Some day I might re-visit this once Microsoft accounts are mandatory for all Minecraft users, since there would most definitely be a way to use their APIs to achieve the same feature.
