# Discourse OAuth2 Basic

**URL:** https://meta.discourse.org/t/discourse-oauth2-basic/33879
**Category:** Plugin
**Tags:** official, oauth2, auth-plugins, included-in-core
**Created:** [September 29, 2015, 4:27pm UTC](https://meta.discourse.org/t/discourse-oauth2-basic/33879 "2015-09-29T16:27:19Z")
**Posts on this page:** 1
**Showing post:** 302

<div class="post-metadata">

### Author: ![Pietro\_Saccardi\_Spak](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pietro_saccardi_spak/32/121488_2.png) [@Pietro\_Saccardi\_Spak](https://meta.discourse.org/u/Pietro_Saccardi_Spak)
#### Post date: [March 17, 2023, 6:37pm UTC](https://meta.discourse.org/t/discourse-oauth2-basic/33879/302 "2023-03-17T18:37:58Z")

</div>

I just got this to work with Authentik OAuth2, however there were some hiccups with the `oauth2 user json url` setting. I used the `user_info` endpoint of Authentik for that (`/application/o/userinfo/`), however I did not know how to map the fields. For anyone looking how to set up Discourse with Authentik’s OAuth2, here’s the summary:

- User id path: `preferred_username`
- Username path: `preferred_username`
- Name path: `name`
- Email path: `email`
- Email verified path: `email_verified`
- Avatar: empty.

I had the following issues:

1. At the beginning, I forgot the trailing slash in the json url `https://DOMAIN/application/o/userinfo/`. This lead to the user info request ([permalink to the source](https://github.com/discourse/discourse-oauth2-basic/blob/1448f05319a0ceb09388946caaac74abb9df12e7/plugin.rb#L231)) to return a 301 HTTP code, which caused the login to fail. I do not know whether the trailing slash should be there by spec, but perhaps it would be good to handle 301 correctly.
2. Debugging this turned out tricky. The `oauth2 debug auth` settings was a lifesaver but… Logster truncates the debug log before actually dumping the meaningful response data. I had to modify manually in the container the log line to

```plaintext
log("user_json_response: #{user_json_response.status} #{user_json_response.headers} #{user_json_response.body}")

```

Perhaps that log line could be updated? I guess it could help other people figure out the json attributes path.

---

_[View the full topic](https://meta.discourse.org/t/discourse-oauth2-basic/33879)._
