500 upon authentik OAuth2/OpenID: login #13769

Closed
opened 2025-11-02 10:52:38 -06:00 by GiteaMirror · 7 comments
Owner

Originally created by @moan0s on GitHub (Nov 29, 2024).

Description

I configured Authentik and Gitea as described in this manual. When trying to login via this OAuth-Flow I encounter a http 500 error and cannot log in via this flow. Reloading does not solve the problem (#5005).

The server log says:

oauth2: error decoding JWT token: jws: invalid token received, not all parts available

Callback that fails with 500: https://git.hyteck.de/user/oauth2/QZT%20Authentik/callback?code=c26c5f75c939524d98f5f67e3d58c6b6&state=08176cae-79d6-46a3-04c7-36670db77079 (not the real code or state).

I specifically configured
samesite: Lax as per https://github.com/go-gitea/gitea/issues/25542, same for GITEA__server__ROOT_URL=https://git.hyteck.de (I also tried including a backslash at the end)

I also set GITEA__oauth2_client__ENABLE_AUTO_REGISTRATION=true

I'm looking for ways to debug this further. Feel free to ask for more information.

Gitea Version

1.22.3

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

https://gist.github.com/moan0s/6e214403d9f1cd15265259455529b3fb

Screenshots

No response

Git Version

No response

Operating System

docker (running on ubuntu)

How are you running Gitea?

Gitea is run as docker container started by a systemd service as deployed by the mash-playbook, same for authentik.
Both run behind Traefik.

Database

PostgreSQL

Originally created by @moan0s on GitHub (Nov 29, 2024). ### Description I configured Authentik and Gitea as described in [this manual](https://docs.goauthentik.io/integrations/services/gitea/). When trying to login via this OAuth-Flow I encounter a http 500 error and cannot log in via this flow. Reloading does not solve the problem (#5005). The server log says: ``` oauth2: error decoding JWT token: jws: invalid token received, not all parts available ``` Callback that fails with `500`: https://git.hyteck.de/user/oauth2/QZT%20Authentik/callback?code=c26c5f75c939524d98f5f67e3d58c6b6&state=08176cae-79d6-46a3-04c7-36670db77079 (not the real code or state). I specifically configured `samesite: Lax` as per https://github.com/go-gitea/gitea/issues/25542, same for `GITEA__server__ROOT_URL=https://git.hyteck.de` (I also tried including a backslash at the end) I also set `GITEA__oauth2_client__ENABLE_AUTO_REGISTRATION=true` I'm looking for ways to debug this further. Feel free to ask for more information. ### Gitea Version 1.22.3 ### Can you reproduce the bug on the Gitea demo site? No ### Log Gist https://gist.github.com/moan0s/6e214403d9f1cd15265259455529b3fb ### Screenshots _No response_ ### Git Version _No response_ ### Operating System docker (running on ubuntu) ### How are you running Gitea? Gitea is run as docker container started by a systemd service as deployed by the [mash-playbook](https://github.com/mother-of-all-self-hosting/mash-playbook), same for authentik. Both run behind Traefik. ### Database PostgreSQL
GiteaMirror added the issue/needs-feedback label 2025-11-02 10:52:38 -06:00
Author
Owner

@KN4CK3R commented on GitHub (Dec 2, 2024):

Works for me by following the linked tutorial. I even tried to use a name with a space like you did but that worked too.

@KN4CK3R commented on GitHub (Dec 2, 2024): Works for me by following the linked tutorial. I even tried to use a name with a space like you did but that worked too.
Author
Owner

@vhaudiquet commented on GitHub (Dec 4, 2024):

I have the exact same issue here ; but it's my first time trying Authentik. I'll try to reinstall and debug, but I don't really know how you could reproduce. It did this not when I try to login but when I try to link my original gitea account with the new authentik one... but I'm not sure that it is relevant to the issue.

Not sure if relevant either, but in my configuration Gitea is internet-faced and authentik is not (authentik is only reachable on my LAN, both are behind traefik, but I have an nginx-proxy-manager behind that traefik instance). But given that I'm doing everything on said LAN, it should not be an issue.

Maybe OP has a more classic setup where everything is reachable ?

@vhaudiquet commented on GitHub (Dec 4, 2024): I have the exact same issue here ; but it's my first time trying Authentik. I'll try to reinstall and debug, but I don't really know how you could reproduce. It did this not when I try to login but when I try to link my original gitea account with the new authentik one... but I'm not sure that it is relevant to the issue. Not sure if relevant either, but in my configuration Gitea is internet-faced and authentik is not (authentik is only reachable on my LAN, both are behind traefik, but I have an nginx-proxy-manager behind that traefik instance). But given that I'm doing everything on said LAN, it should not be an issue. Maybe OP has a more classic setup where everything is reachable ?
Author
Owner

@moan0s commented on GitHub (Dec 11, 2024):

@KN4CK3R Okay, well I guess I check again if I really followed every step of the tutorial. Either way, the error message should be more clear IMHO.

Yeah, in my setup everything is publicly reachable

@moan0s commented on GitHub (Dec 11, 2024): @KN4CK3R Okay, well I guess I check again if I really followed every step of the tutorial. Either way, the error message should be more clear IMHO. Yeah, in my setup everything is publicly reachable
Author
Owner

@lautriva commented on GitHub (Dec 13, 2024):

Same problem for me

Maybe it would help, I'm using those configs:

DISABLE_REGISTRATION = true
REQUIRE_SIGNIN_VIEW = true

The idea is that the SSO will only let users to link their Authentik account with their existing gitea one

(no registration are allowed to let me control who can access to my instance)

@lautriva commented on GitHub (Dec 13, 2024): Same problem for me Maybe it would help, I'm using those configs: ``` DISABLE_REGISTRATION = true REQUIRE_SIGNIN_VIEW = true ``` The idea is that the SSO will only let users to link their Authentik account with their existing gitea one (no registration are allowed to let me control who can access to my instance)
Author
Owner

@kat4ex commented on GitHub (Dec 21, 2024):

It seems that gitea has some problems with JWE.

Just turn off token encryption in the authentik provider.
изображение

@kat4ex commented on GitHub (Dec 21, 2024): It seems that gitea has some problems with JWE. Just turn off token encryption in the authentik provider. ![изображение](https://github.com/user-attachments/assets/aa4710bd-9392-449c-8db1-5d2ff94c67c8)
Author
Owner

@moan0s commented on GitHub (Dec 21, 2024):

Thank you so much, that was it!

@moan0s commented on GitHub (Dec 21, 2024): Thank you so much, that was it!
Author
Owner

@VIXNESS commented on GitHub (Jan 9, 2025):

It's work too:
copy from gitea config app.ini field JWT_SECRET in [oauth2] to authentik config field: Encryption Key

@VIXNESS commented on GitHub (Jan 9, 2025): It's work too: copy from gitea config `app.ini` field `JWT_SECRET` in `[oauth2]` to authentik config field: Encryption Key
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#13769