mirror of
https://github.com/go-gitea/gitea.git
synced 2026-03-12 18:48:08 -05:00
Adding OAuth2 Authentication Sources through the CLI Requires Manual Intervention through UI in order to work #4048
Closed
opened 2025-11-02 05:35:34 -06:00 by GiteaMirror
·
15 comments
No Branch/Tag Specified
main
release/v1.25
release/v1.24
release/v1.23
release/v1.22
release/v1.21
release/v1.20
release/v1.19
release/v1.18
release/v1.17
release/v1.16
release/v1.15
release/v1.14
release/v1.13
release/v1.12
release/v1.11
release/v1.10
release/v1.9
release/v1.8
v1.25.3
v1.25.2
v1.25.1
v1.25.0
v1.24.7
v1.25.0-rc0
v1.26.0-dev
v1.24.6
v1.24.5
v1.24.4
v1.24.3
v1.24.2
v1.24.1
v1.24.0
v1.23.8
v1.24.0-rc0
v1.25.0-dev
v1.23.7
v1.23.6
v1.23.5
v1.23.4
v1.23.3
v1.23.2
v1.23.1
v1.23.0
v1.23.0-rc0
v1.24.0-dev
v1.22.6
v1.22.5
v1.22.4
v1.22.3
v1.22.2
v1.22.1
v1.22.0
v1.23.0-dev
v1.22.0-rc1
v1.21.11
v1.22.0-rc0
v1.21.10
v1.21.9
v1.21.8
v1.21.7
v1.21.6
v1.21.5
v1.21.4
v1.21.3
v1.21.2
v1.20.6
v1.21.1
v1.21.0
v1.21.0-rc2
v1.21.0-rc1
v1.20.5
v1.22.0-dev
v1.21.0-rc0
v1.20.4
v1.20.3
v1.20.2
v1.20.1
v1.20.0
v1.19.4
v1.21.0-dev
v1.20.0-rc2
v1.20.0-rc1
v1.20.0-rc0
v1.19.3
v1.19.2
v1.19.1
v1.19.0
v1.19.0-rc1
v1.20.0-dev
v1.19.0-rc0
v1.18.5
v1.18.4
v1.18.3
v1.18.2
v1.18.1
v1.18.0
v1.17.4
v1.18.0-rc1
v1.19.0-dev
v1.18.0-rc0
v1.17.3
v1.17.2
v1.17.1
v1.17.0
v1.17.0-rc2
v1.16.9
v1.17.0-rc1
v1.18.0-dev
v1.16.8
v1.16.7
v1.16.6
v1.16.5
v1.16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.4.0-rc2
v1.3.3
v1.4.0-rc1
v1.3.2
v1.3.1
v1.3.0
v1.3.0-rc2
v1.3.0-rc1
v1.2.3
v1.2.2
v1.2.1
v1.2.0
v1.2.0-rc3
v1.2.0-rc2
v1.1.4
v1.2.0-rc1
v1.1.3
v1.1.2
v1.1.1
v1.1.0
v1.0.2
v1.0.1
v1.0.0
v0.9.99
Labels
Clear labels
$20
$250
$50
$500
backport/done
💎 Bounty
docs-update-needed
good first issue
hacktoberfest
issue/bounty
issue/confirmed
issue/critical
issue/duplicate
issue/needs-feedback
issue/not-a-bug
issue/regression
issue/stale
issue/workaround
lgtm/need 2
modifies/api
modifies/translation
outdated/backport/v1.18
outdated/theme/markdown
outdated/theme/timetracker
performance/bigrepo
performance/cpu
performance/memory
performance/speed
pr/breaking
proposal/accepted
proposal/rejected
pr/wip
pull-request
reviewed/wontfix
💰 Rewarded
skip-changelog
status/blocked
topic/accessibility
topic/api
topic/authentication
topic/build
topic/code-linting
topic/commit-signing
topic/content-rendering
topic/deployment
topic/distribution
topic/federation
topic/gitea-actions
topic/issues
topic/lfs
topic/mobile
topic/moderation
topic/packages
topic/pr
topic/projects
topic/repo
topic/repo-migration
topic/security
topic/theme
topic/ui
topic/ui-interaction
topic/ux
topic/webhooks
topic/wiki
type/bug
type/deprecation
type/docs
type/enhancement
type/feature
type/miscellaneous
type/proposal
type/question
type/refactoring
type/summary
type/testing
type/upstream
Mirrored from GitHub Pull Request
Milestone
No items
No Milestone
Projects
Clear projects
No project
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/gitea#4048
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @ilyakrasnovsky on GitHub (Oct 2, 2019).
First off, thanks for a great product so far!
[x]):Description
The most straightforward way to reproduce this IMO is:
gitea admin auth add-oauth --name keycloakoidc --provider openidConnect --key gitea --secret <MY-GITEA-CLIENT-SECRET> --auto-discover-url http://<MY-KEYCLOAK-DOMAIN>/auth/realms/<MY-KEYCLOAK-REALM>/.well-known/openid-configuration --config=/home/gitea/conf/app.ini/home/gitea/gitea admin auth add-oauth --name gitlab --provider gitlab --key gitea --secret <MY-GITEA-CLIENT-SECRET> --custom-auth-url https://gitlab.com/oauth/authorize --custom-token-url https://gitlab.com/oauth/token --custom-profile-url https://gitlab.com/api/v3/user --config=/home/gitea/conf/app.iniThese commands both succeed and you get the appropriate
Sign in withbuttons appearing on the sign in page, as shown below:However, clicking on this link immediately gives a 500 error (screenshot below):
The server logs don't produce much more there, just
[Macaron] 2019-10-02 17:02:02: Completed GET /user/oauth2/gitlab 500 Internal Server Error in 7.243256ms.However : if you had
DISABLE_REGISTRATION = falsein yourapp.ini, and at this point you register as a local (non-external) user with admin privileges through the UI, and then go toSite Administration->Authentication Sources, click to edit the authentication source that you just created through the CLI, and just click update (no changes whatsoever, see below)Then you will notice that if you sign out and go back to the sign in page, then clicking the
Sign in withGitlab button works, it takes you out to Gitlab.com instead of returning a 500.In summary, as the title of this issue suggests, creating OAuth2 authentication sources through the CLI requires a manual, one-time intervention through the UI to make them work. In most cases this isn't a big deal, but it's a showstopper if you're trying to automate the deployment of Gitea. Thanks!
@ilyakrasnovsky commented on GitHub (Oct 2, 2019):
#183 has a good discussion that's relevant to this
@ilyakrasnovsky commented on GitHub (Oct 3, 2019):
I've been fooling around with this more after building Gitea from source. I've narrowed it down to a "no provider found" error in the
SignInOAuthfunction inrouters/user/auth.go(maybe similar to #5380, but I'm certain my auto-discovery URL is right because it works if I fill it in through the UI). I also noticed that simply restarting the Gitea application after invoking thegitea admin auth add-oauthcommands described above, I no longer get the 500 on sign-in, without UI intervention. So that's an ugly but viable workaround. Basically, deploy Gitea, run the CLI command to add an auth source, then restart Gitea. This smells like a caching issue. I'm not too hot with Go or Macaron right now so perhaps I'll revisit when I'm better educated :)@guillep2k commented on GitHub (Oct 3, 2019):
Sorry if the question is too dumb but, have you tried using quotes in your parameters when invoking from shell?
For instance, change:
--auto-discover-url http://<MY-KEYCLOAK-DOMAIN>into
--auto-discover-url "http://<MY-KEYCLOAK-DOMAIN>"A big gotcha with URLs is that they usually contain characters like
?and&that are special delimiters in most shells.@ilyakrasnovsky commented on GitHub (Oct 3, 2019):
@guillep2k I did try that, unfortunately I still got a 500. Inspecting it through the UI (after it's populated through the CLI) yields the exact URL I want. The actual request to
user/oauth2/keycloakoidc(or whatever you named your authentication source) stills fails unless I click "update" through the UI, or restart the application.@stale[bot] commented on GitHub (Dec 2, 2019):
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.
@bendem commented on GitHub (Jun 17, 2020):
Came here to say this, I've tried many things, checked the
login_sourcetable before and after updating manually from the UI, I'm not sure what's different.@traverseda commented on GitHub (Aug 14, 2020):
Unfortunately a simple restart doesn't seem to fix this. I think this means that this isn't going to be viable for my employer.
@bendem commented on GitHub (Aug 18, 2020):
I confirm a restart fixes the problem, if it doesn't for you, you probably have another problem. Does it work when you input the exact same config in the web UI?
@traverseda commented on GitHub (Aug 18, 2020):
I'll investigate further. It's possible that that I've got something mistyped in the command line. Thanks for letting me know.
@traverseda commented on GitHub (Aug 18, 2020):
Can confirm that this works.
It appears that I misspelled
--provider openidConnect, which was causing that to fail silently.@daniil-pankratov commented on GitHub (Dec 9, 2020):
Hi.
Are there any news about this bug? @lunny
@lunny commented on GitHub (Dec 19, 2020):
It seems the command code is the same as creating OAuth2 login source via UI. The only different is
@daniil-pankratov commented on GitHub (Dec 19, 2020):
Could
IsSyncEnabledparameter lead to this bug?@lunny commented on GitHub (Dec 19, 2020):
I don't think so.
@bendem commented on GitHub (Dec 19, 2020):
You are showing the difference in database saving. My guess is: the data from that table is only loaded on application start. When adding from the UI it is added to the in-memory providers, when called from the cli, it is not. That's why a restart fixes the problem.
19 Dec 2020 09:42:57 Lunny Xiao notifications@github.com: