First authorization via OAUTH fails #13195

Open
opened 2025-11-02 10:34:27 -06:00 by GiteaMirror · 22 comments
Owner

Originally created by @Remmert-PBE on GitHub (Jun 24, 2024).

Description

The first authorization attempt after some hours fails, while the second one directly afterwards succeeds:

== 1. try ==
git.exe push --progress  -- "origin" master:master
remote: Verify
fatal: Authentication failed for 'https://git.company.intern/Organization/Product.git/'

git did not exit cleanly (exit code 128) (3687 ms @ 12.06.2024 14:38:16)

== 2. try ==
git.exe push --progress  -- "origin" master:master
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 20 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 1.03 KiB | 1.03 MiB/s, done.
Total 3 (delta 2), reused 0 (delta 0), pack-reused 0 (from 0)
remote: . Processing 1 references
remote: Processed 1 references in total
To https://git.company.intern/Organization/Product.git
11111111..111111 master -> master

Success (6407 ms @ 12.06.2024 14:38:34)

The gitea logfile shows that it tries to login with the user "OAUTH_USER" to our LDAP server, like it is saved by the Git Credential Manager:
Screenshot 2024-06-24 084634

2024/06/24 07:53:04 ...eb/routing/logger.go:102:func1() [I] router: completed GET /Organization/Product.git/info/refs?service=git-receive-pack for 192.168.0.10:0, 401 Unauthorized in 4.9ms @ repo/githttp.go:532(repo.GetInfoRefs)
2024/06/24 07:53:08 ...dap/source_search.go:95:findUserDN() [D] Failed search using filter[(&(objectCategory=Person)(|(memberOf=CN=git-developer,OU=Securitygroups,OU=Location,DC=company,DC=intern)(memberOf=CN=git-admin,OU=Securitygroups,OU=Location,DC=company,DC=intern)(memberOf=CN=git-service,OU=Securitygroups,OU=Location,DC=company,DC=intern))(sAMAccountName=OAUTH_USER)(!(UserAccountControl:1.2.840.113556.1.4.803:=2)))]: <nil>
2024/06/24 07:53:08 ...vices/auth/signin.go:114:UserSignIn() [D] Failed to login 'OAUTH_USER' via 'CompanyAD': user does not exist [uid: 0, name: OAUTH_USER, keyid: 0]
2024/06/24 07:53:08 routers/web/web.go:123:func7() [E] Failed to verify user: user does not exist [uid: 0, name: OAUTH_USER, keyid: 0]
2024/06/24 07:53:08 ...eb/routing/logger.go:102:func1() [I] router: completed GET /Organization/Product.git/info/refs?service=git-receive-pack for 192.168.0.10:0, 401 Unauthorized in 137.8ms @ web/web.go:120(web.Routes.webAuth)
2024/06/24 07:53:08 ...dap/source_search.go:95:findUserDN() [D] Failed search using filter[(&(objectCategory=Person)(|(memberOf=CN=git-developer,OU=Securitygroups,OU=Location,DC=company,DC=intern)(memberOf=CN=git-admin,OU=Securitygroups,OU=Location,DC=company,DC=intern)(memberOf=CN=git-service,OU=Securitygroups,OU=Location,DC=company,DC=intern))(sAMAccountName=OAUTH_USER)(!(UserAccountControl:1.2.840.113556.1.4.803:=2)))]: <nil>
2024/06/24 07:53:08 ...vices/auth/signin.go:114:UserSignIn() [D] Failed to login 'OAUTH_USER' via 'CompanyAD': user does not exist [uid: 0, name: OAUTH_USER, keyid: 0]
2024/06/24 07:53:08 routers/web/web.go:123:func7() [E] Failed to verify user: user does not exist [uid: 0, name: OAUTH_USER, keyid: 0]
2024/06/24 07:53:08 ...eb/routing/logger.go:102:func1() [I] router: completed GET /Organization/Product.git/info/refs?service=git-receive-pack for 192.168.0.10:0, 401 Unauthorized in 59.1ms @ web/web.go:120(web.Routes.webAuth)

2024/06/24 07:53:11 ...eb/routing/logger.go:102:func1() [I] router: completed GET /Organization/Product.git/info/refs?service=git-receive-pack for 192.168.0.10:0, 401 Unauthorized in 1.8ms @ repo/githttp.go:532(repo.GetInfoRefs)
2024/06/24 07:53:11 ...eb/routing/logger.go:102:func1() [I] router: completed POST /login/oauth/access_token for 192.168.0.10:0, 200 OK in 23.1ms @ auth/oauth.go:618(auth.AccessTokenOAuth)
2024/06/24 07:53:11 ...dules/git/command.go:290:Run() [D] git.Command.RunDir(d:\Data\Repositories\Organization\Product.git): "C:\\Program Files\\Git\\cmd\\git.exe" -c protocol.version=2 -c credential.helper= -c filter.lfs.required= -c filter.lfs.smudge= -c filter.lfs.clean= receive-pack --stateless-rpc --advertise-refs .
2024/06/24 07:53:12 ...eb/routing/logger.go:102:func1() [I] router: completed GET /Organization/Product.git/info/refs?service=git-receive-pack for 192.168.0.10:0, 200 OK in 96.3ms @ repo/githttp.go:532(repo.GetInfoRefs)

The authorization after the initial error works for a few hours, but after a while it reappears (token becomes invalid?).

The credential settings in git are:

credential.helper=
credential.helper=C:/Users/pbe/.dotnet/tools/git-credential-manager.exe
credential.https://git.company.intern.provider=generic

Gitea Version

1.21.11

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

https://gist.github.com/Remmert-PBE/959e1e243a2d8243a757aef754571270

Screenshots

No response

Git Version

git version 2.45.2.windows.1

Operating System

Windows Server 2019 Standard

How are you running Gitea?

Running as a service on a windows server. Behind a nginx reverse proxy (configured like the example in the gitea docs)

Database

MSSQL

Originally created by @Remmert-PBE on GitHub (Jun 24, 2024). ### Description The first authorization attempt after some hours fails, while the second one directly afterwards succeeds: ``` == 1. try == git.exe push --progress -- "origin" master:master remote: Verify fatal: Authentication failed for 'https://git.company.intern/Organization/Product.git/' git did not exit cleanly (exit code 128) (3687 ms @ 12.06.2024 14:38:16) == 2. try == git.exe push --progress -- "origin" master:master Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Delta compression using up to 20 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 1.03 KiB | 1.03 MiB/s, done. Total 3 (delta 2), reused 0 (delta 0), pack-reused 0 (from 0) remote: . Processing 1 references remote: Processed 1 references in total To https://git.company.intern/Organization/Product.git 11111111..111111 master -> master Success (6407 ms @ 12.06.2024 14:38:34) ``` The gitea logfile shows that it tries to login with the user "OAUTH_USER" to our LDAP server, like it is saved by the Git Credential Manager: ![Screenshot 2024-06-24 084634](https://github.com/go-gitea/gitea/assets/141999945/cab8ff9d-9ef7-48c3-8ba5-4e074e77f113) ``` 2024/06/24 07:53:04 ...eb/routing/logger.go:102:func1() [I] router: completed GET /Organization/Product.git/info/refs?service=git-receive-pack for 192.168.0.10:0, 401 Unauthorized in 4.9ms @ repo/githttp.go:532(repo.GetInfoRefs) 2024/06/24 07:53:08 ...dap/source_search.go:95:findUserDN() [D] Failed search using filter[(&(objectCategory=Person)(|(memberOf=CN=git-developer,OU=Securitygroups,OU=Location,DC=company,DC=intern)(memberOf=CN=git-admin,OU=Securitygroups,OU=Location,DC=company,DC=intern)(memberOf=CN=git-service,OU=Securitygroups,OU=Location,DC=company,DC=intern))(sAMAccountName=OAUTH_USER)(!(UserAccountControl:1.2.840.113556.1.4.803:=2)))]: <nil> 2024/06/24 07:53:08 ...vices/auth/signin.go:114:UserSignIn() [D] Failed to login 'OAUTH_USER' via 'CompanyAD': user does not exist [uid: 0, name: OAUTH_USER, keyid: 0] 2024/06/24 07:53:08 routers/web/web.go:123:func7() [E] Failed to verify user: user does not exist [uid: 0, name: OAUTH_USER, keyid: 0] 2024/06/24 07:53:08 ...eb/routing/logger.go:102:func1() [I] router: completed GET /Organization/Product.git/info/refs?service=git-receive-pack for 192.168.0.10:0, 401 Unauthorized in 137.8ms @ web/web.go:120(web.Routes.webAuth) 2024/06/24 07:53:08 ...dap/source_search.go:95:findUserDN() [D] Failed search using filter[(&(objectCategory=Person)(|(memberOf=CN=git-developer,OU=Securitygroups,OU=Location,DC=company,DC=intern)(memberOf=CN=git-admin,OU=Securitygroups,OU=Location,DC=company,DC=intern)(memberOf=CN=git-service,OU=Securitygroups,OU=Location,DC=company,DC=intern))(sAMAccountName=OAUTH_USER)(!(UserAccountControl:1.2.840.113556.1.4.803:=2)))]: <nil> 2024/06/24 07:53:08 ...vices/auth/signin.go:114:UserSignIn() [D] Failed to login 'OAUTH_USER' via 'CompanyAD': user does not exist [uid: 0, name: OAUTH_USER, keyid: 0] 2024/06/24 07:53:08 routers/web/web.go:123:func7() [E] Failed to verify user: user does not exist [uid: 0, name: OAUTH_USER, keyid: 0] 2024/06/24 07:53:08 ...eb/routing/logger.go:102:func1() [I] router: completed GET /Organization/Product.git/info/refs?service=git-receive-pack for 192.168.0.10:0, 401 Unauthorized in 59.1ms @ web/web.go:120(web.Routes.webAuth) 2024/06/24 07:53:11 ...eb/routing/logger.go:102:func1() [I] router: completed GET /Organization/Product.git/info/refs?service=git-receive-pack for 192.168.0.10:0, 401 Unauthorized in 1.8ms @ repo/githttp.go:532(repo.GetInfoRefs) 2024/06/24 07:53:11 ...eb/routing/logger.go:102:func1() [I] router: completed POST /login/oauth/access_token for 192.168.0.10:0, 200 OK in 23.1ms @ auth/oauth.go:618(auth.AccessTokenOAuth) 2024/06/24 07:53:11 ...dules/git/command.go:290:Run() [D] git.Command.RunDir(d:\Data\Repositories\Organization\Product.git): "C:\\Program Files\\Git\\cmd\\git.exe" -c protocol.version=2 -c credential.helper= -c filter.lfs.required= -c filter.lfs.smudge= -c filter.lfs.clean= receive-pack --stateless-rpc --advertise-refs . 2024/06/24 07:53:12 ...eb/routing/logger.go:102:func1() [I] router: completed GET /Organization/Product.git/info/refs?service=git-receive-pack for 192.168.0.10:0, 200 OK in 96.3ms @ repo/githttp.go:532(repo.GetInfoRefs) ``` The authorization after the initial error works for a few hours, but after a while it reappears (token becomes invalid?). The credential settings in git are: ``` credential.helper= credential.helper=C:/Users/pbe/.dotnet/tools/git-credential-manager.exe credential.https://git.company.intern.provider=generic ``` ### Gitea Version 1.21.11 ### Can you reproduce the bug on the Gitea demo site? No ### Log Gist https://gist.github.com/Remmert-PBE/959e1e243a2d8243a757aef754571270 ### Screenshots _No response_ ### Git Version git version 2.45.2.windows.1 ### Operating System Windows Server 2019 Standard ### How are you running Gitea? Running as a service on a windows server. Behind a nginx reverse proxy (configured like the example in the gitea docs) ### Database MSSQL
GiteaMirror added the type/upstreamissue/workaroundissue/not-a-bug labels 2025-11-02 10:34:27 -06:00
Author
Owner

@Xulunix commented on GitHub (Jun 25, 2024):

I noticed the same issue using a similar setup (OIDC instead of LDAP).
It works if tried again but some tools check the remote periodically and ask the user to login again if authentication fails.

@Xulunix commented on GitHub (Jun 25, 2024): I noticed the same issue using a similar setup (OIDC instead of LDAP). It works if tried again but some tools check the remote periodically and ask the user to login again if authentication fails.
Author
Owner

@yp05327 commented on GitHub (Jun 27, 2024):

It seems that this issue is similar to #30991?

Maybe OAUTH_USER comes from here:
e124b8bb8f/src/shared/Core/GenericOAuthConfig.cs (L143)

@yp05327 commented on GitHub (Jun 27, 2024): It seems that this issue is similar to #30991? Maybe `OAUTH_USER` comes from here: https://github.com/git-ecosystem/git-credential-manager/blob/e124b8bb8f4a53301e0d9d947c075519f75ff222/src/shared/Core/GenericOAuthConfig.cs#L143
Author
Owner

@yp05327 commented on GitHub (Jun 27, 2024):

I found a related issue ( maybe ) in GCM:
https://github.com/git-ecosystem/git-credential-manager/issues/1408

Maybe this is a problem from upstream (not directly related) ?

@yp05327 commented on GitHub (Jun 27, 2024): I found a related issue ( maybe ) in GCM: https://github.com/git-ecosystem/git-credential-manager/issues/1408 Maybe this is a problem from upstream (not directly related) ?
Author
Owner

@Remmert-PBE commented on GitHub (Jun 27, 2024):

@yp05327 Good find, thats exactly what happens on my system. I ran a GCM_TRACE a few days back and it is similar to the one in the gcm issue. In my log the first push ends with the command erase and only on the 2nd push a new token is saved.

See https://gist.github.com/Remmert-PBE/1ccecd8d82c4b19d700835bff1b3567b

Now the question is, which tool is at fault?

@Remmert-PBE commented on GitHub (Jun 27, 2024): @yp05327 Good find, thats exactly what happens on my system. I ran a GCM_TRACE a few days back and it is similar to the one in the [gcm issue](https://github.com/git-ecosystem/git-credential-manager/issues/1408). In my log the first push ends with the command erase and only on the 2nd push a new token is saved. See https://gist.github.com/Remmert-PBE/1ccecd8d82c4b19d700835bff1b3567b Now the question is, which tool is at fault?
Author
Owner

@meruiden commented on GitHub (Jul 13, 2024):

I have the same, after a little while, when I push again, the first time always fails, second time succeeds. im also logged in via the vscode -> oauth in browser

@meruiden commented on GitHub (Jul 13, 2024): I have the same, after a little while, when I push again, the first time always fails, second time succeeds. im also logged in via the vscode -> oauth in browser
Author
Owner

@uujwnqjgim commented on GitHub (Aug 9, 2024):

First push fails with:

remote: Verify
fatal: Authentication failed for ...

second git push is ok

@uujwnqjgim commented on GitHub (Aug 9, 2024): First push fails with: remote: Verify fatal: Authentication failed for ... second git push is ok
Author
Owner

@257er commented on GitHub (Aug 30, 2024):

same issue here.

@257er commented on GitHub (Aug 30, 2024): same issue here.
Author
Owner

@eeyrjmr commented on GitHub (Sep 10, 2024):

same, this only just started to be an issue

@eeyrjmr commented on GitHub (Sep 10, 2024): same, this only just started to be an issue
Author
Owner

@eeyrjmr commented on GitHub (Sep 11, 2024):

I can't be sure but I think this started when I stopped using the gogit build of gitea... This was partially due to sha256
I will see if gogit windows build still works

@eeyrjmr commented on GitHub (Sep 11, 2024): I can't be sure but I think this started when I stopped using the gogit build of gitea... This was partially due to sha256 I will see if gogit windows build still works
Author
Owner

@jonathanduke commented on GitHub (Sep 12, 2024):

The same thing has been happening to me recently. Since some of my pulls/pushes are automated to happen at night, it's a real pain.

I think it started after upgrading git-for-windows to 2.45.2.windows.1 and switching to GCM. A workaround has been discussed in the forums here:
https://forum.gitea.com/t/authentication-failed-for-but-running-the-command-again-works/8521

That does work to make it occur less often throughout the day if I set it to 24 hours vs. 1 hour, but it will still expire eventually. So, before my automated processes, I just made sure that I do an extra "git push" to force that expired token to be deleted, so the rest of the batch still works. That seems to get around the problem for now.

@jonathanduke commented on GitHub (Sep 12, 2024): The same thing has been happening to me recently. Since some of my pulls/pushes are automated to happen at night, it's a real pain. I think it started after upgrading git-for-windows to 2.45.2.windows.1 and switching to GCM. A workaround has been discussed in the forums here: https://forum.gitea.com/t/authentication-failed-for-but-running-the-command-again-works/8521 That does work to make it occur less often throughout the day if I set it to 24 hours vs. 1 hour, but it will still expire eventually. So, before my automated processes, I just made sure that I do an extra "git push" to force that expired token to be deleted, so the rest of the batch still works. That seems to get around the problem for now.
Author
Owner

@lyleubben commented on GitHub (Sep 26, 2024):

Can confirm the same issue using git manually. Works on the second call. I believe this is also causing actions to fail on the checkout step.

@lyleubben commented on GitHub (Sep 26, 2024): Can confirm the same issue using git manually. Works on the second call. I believe this is also causing actions to fail on the checkout step.
Author
Owner

@vansanper commented on GitHub (Oct 2, 2024):

Same issue here for my team, tried the workaround to see if it at least mitigates the problem to once a day...

@vansanper commented on GitHub (Oct 2, 2024): Same issue here for my team, tried the workaround to see if it at least mitigates the problem to once a day...
Author
Owner

@bvandevliet commented on GitHub (Dec 9, 2024):

I also still face this issue. Quite annoying tbh.

@bvandevliet commented on GitHub (Dec 9, 2024): I also still face this issue. Quite annoying tbh.
Author
Owner

@seepine commented on GitHub (Jan 22, 2025):

I want to know if there are any good solutions at present, such as rolling back the git-for-windows version? Or rolling back the gitea version?

@seepine commented on GitHub (Jan 22, 2025): I want to know if there are any good solutions at present, such as rolling back the git-for-windows version? Or rolling back the gitea version?
Author
Owner

@eeyrjmr commented on GitHub (Jan 22, 2025):

I want to know if there are any good solutions at present, such as rolling back the git-for-windows version? Or rolling back the gitea version?

It would be rolling back git-for-windows to the version that used a windows specific solution.
This is extremely frustrating but we are dependant on git-for-windows to fix. There are several open issues on this over at that repository, using different forges

@eeyrjmr commented on GitHub (Jan 22, 2025): > I want to know if there are any good solutions at present, such as rolling back the git-for-windows version? Or rolling back the gitea version? It would be rolling back git-for-windows to the version that used a windows specific solution. This is extremely frustrating but we are dependant on git-for-windows to fix. There are several open issues on this over at that repository, using different forges
Author
Owner

@Remmert-PBE commented on GitHub (Jan 23, 2025):

I got it working by prepending the username to the remote url, i.e. https://USER@git.company.intern/Organization/Product.git/. This prevents GCM from saving the login token with the dummy username 'OAUTH_USER'.

@Remmert-PBE commented on GitHub (Jan 23, 2025): I got it working by prepending the username to the remote url, i.e. `https://USER@git.company.intern/Organization/Product.git/`. This prevents GCM from saving the login token with the dummy username 'OAUTH_USER'.
Author
Owner

@becm commented on GitHub (Feb 6, 2025):

It's a GCM issue, when it arbitrarily started to enforce OAuth when assuming a Gitea remote.

The issue is that token expiration dates are (still) not saved, so there is currently no other way than try and fail.
While other specialized providers for (e.g.) Azure and Bitbucket have some builtin wayshacks to check this internally, there is no extra handling for the generic case.

Mitigations boil down to

  • just accept the 2nd try or
  • initially invalidate the OAuth config by setting credential.oauthAuthorizeEndpoint=// (not viable with 2FA) or
  • replace the git:https://<server> password entry with an application token
    (no expiry issue and better access restriction)
@becm commented on GitHub (Feb 6, 2025): It's a GCM issue, when it arbitrarily started to enforce OAuth when assuming a [Gitea remote](https://github.com/git-ecosystem/git-credential-manager/commit/c512d1b0e7320ab2fc7cfac6fe1eafb90af0b273#diff-e79ea97a2573c4fff5ad878dd4a4e5df2b1a6a29c93d84b0ff5926f8de9ac3e3L12). The issue is that token expiration dates are ([still](/git-ecosystem/git-credential-manager/pull/1464)) not saved, so there is currently no other way than try and fail. While other specialized providers for (e.g.) Azure and Bitbucket have some builtin ~ways~hacks to check this internally, there is no extra handling for the generic case. Mitigations boil down to - _just accept the 2nd try_ or - initially invalidate the OAuth config by setting `credential.oauthAuthorizeEndpoint=//` (not viable with 2FA) or - replace the `git:https://<server>` password entry with an application token (no expiry issue and better access restriction)
Author
Owner

@wantong commented on GitHub (Apr 3, 2025):

i am facing the same issue, as enable LDAP auth for gitea, my users need to push twice to get checkin work done. is there any progress one this problem?

@wantong commented on GitHub (Apr 3, 2025): i am facing the same issue, as enable LDAP auth for gitea, my users need to push twice to get checkin work done. is there any progress one this problem?
Author
Owner

@seepine commented on GitHub (Apr 11, 2025):

Change app.ini expiration time can help me, although it's not the ultimate solution.

[oauth]
ACCESS_TOKEN_EXPIRATION_TIME = 86400

https://forum.gitea.com/t/authentication-failed-for-but-running-the-command-again-works/8521/2

@seepine commented on GitHub (Apr 11, 2025): Change `app.ini` expiration time can help me, although it's not the ultimate solution. ```ini [oauth] ACCESS_TOKEN_EXPIRATION_TIME = 86400 ``` https://forum.gitea.com/t/authentication-failed-for-but-running-the-command-again-works/8521/2
Author
Owner

@becm commented on GitHub (Apr 27, 2025):

Expiry detection for JWT credentials (as used by Gitea) might actually be fairly trivial:

But the GCM project seems to be (currently) unmaintained, fixes and improvements are not processed.

Only thing possible on the Gitea side would be to further improve the (original) remote: Verify message.

@becm commented on GitHub (Apr 27, 2025): Expiry detection for JWT credentials (as used by Gitea) might actually be fairly trivial: - git-ecosystem/git-credential-manager#1837 But the GCM project seems to be (currently) unmaintained, [fixes](/git-ecosystem/git-credential-manager/pull/1838) and improvements are not processed. Only thing possible on the Gitea side would be to [further improve](https://github.com/go-gitea/gitea/commit/5dddcc1773b9245a7bcd1f71a83a0681ea541538) the (original) `remote: Verify` message.
Author
Owner

@w3ori commented on GitHub (Jun 20, 2025):

Same issue with LDAP.

@w3ori commented on GitHub (Jun 20, 2025): Same issue with LDAP.
Author
Owner

@zc-devs commented on GitHub (Oct 7, 2025):

https://github.com/go-gitea/gitea/issues/31470#issuecomment-2641395661:

replace the git:https:// password entry with an application token

  1. Generate token
gitea admin user generate-access-token --username myname --token-name mytoken
  1. Open Control Panel\All Control Panel Items\Credential Manager
  2. Choose Windows Credentials
  3. Select credential and click Edit
  4. Change username from OAUTH_USER to your myname and set the token from step 1 in the password field.
Image
@zc-devs commented on GitHub (Oct 7, 2025): https://github.com/go-gitea/gitea/issues/31470#issuecomment-2641395661: > replace the git:https://<server> password entry with an application token 1. [Generate token](https://docs.gitea.com/administration/command-line#admin) ``` gitea admin user generate-access-token --username myname --token-name mytoken ``` 2. Open `Control Panel\All Control Panel Items\Credential Manager` 3. Choose `Windows Credentials` 4. Select credential and click `Edit` 5. Change username from `OAUTH_USER` to your `myname` and set the token from step 1 in the `password` field. <img width="1026" height="324" alt="Image" src="https://github.com/user-attachments/assets/90f15bc5-9f24-467c-a025-de6f57f21dc1" />
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#13195