git-credential-oauth icon indicating copy to clipboard operation
git-credential-oauth copied to clipboard

Custom GitLab instance support

Open hickford opened this issue 2 years ago • 8 comments

To use with a custom GitLab instance, eg. gitlab.example.com

  1. Register an OAuth application on the host
    • Browse to eg. https://gitlab.example.com/-/profile/applications
    • Specify name git-credential-oauth
    • Specify redirect URI http://127.0.0.1
    • Uncheck 'Confidential'
    • Select scopes read_repository and write_repository
    • Click button 'Save application'
  2. Copy the generated client id
  3. Run the command below, adjusting the URL and client id
  4. Share this command with colleagues
git config --global credential.https://gitlab.example.com.oauthClientId <CLIENTID>

If you'd like universal GitLab support without configuration, please vote for issue https://gitlab.com/gitlab-org/gitlab/-/issues/374172

hickford avatar Apr 18 '23 22:04 hickford

Screenshot image

hickford avatar Apr 20 '23 08:04 hickford

Does this work this 2FA enabled?

alexeadem avatar Feb 19 '24 18:02 alexeadem

Does this work this 2FA enabled?

@alexeadem Yes

hickford avatar Feb 19 '24 19:02 hickford

Does this work this 2FA enabled?

@alexeadem Yes

I'm getting this error.

GitLab Community Edition 14.0.12 git version 2.43.0

Please complete authentication in your browser...
https:///$GIT_HOST/oauth/authorize?client_id=0c5c59af20013c6ed40b17ac7e8532fb7aad6b6aa96811e56d14f2c071c8e8b8&code_challenge=ZwvNnQOj8oKBv5mn-wHiUfhOuLmGsN6KXLogGzbT7Do&code_challenge_method=S256&redirect_uri=http%3A%2F%2F127.0.0.1%3A40859&response_type=code&scope=read_repository+write_repository&state=S0ynjJY_0VVp2STKRYYFOdIEnvL1oxn-81YrB5gFB-0
remote: HTTP Basic: Access denied
fatal: Authentication failed for 'https://$GIT_HOST/$USER/$REPO-src.git

Browser redirect says authentication is successful....

Success. You may close this page and return to Git.

—[git-credential-oauth](https://github.com/hickford/git-credential-oauth)

alexeadem avatar Feb 19 '24 20:02 alexeadem

I'm getting this error.

remote: HTTP Basic: Access denied
fatal: Authentication failed for 'https://$GIT_HOST/$USER/$REPO-src.git

@alexeadem Are you sure you have permissions to access that specific repo? Are you trying to fetch or pull?

You can debug some more:

 echo url=https://gitlab.example.com | git credential fill

The username must be oauth2, not your username.

hickford avatar Feb 19 '24 20:02 hickford

I'm getting this error.

remote: HTTP Basic: Access denied
fatal: Authentication failed for 'https://$GIT_HOST/$USER/$REPO-src.git

@alexeadem Are you sure you have permissions to access that specific repo? Are you trying to fetch or pull?

I just tested on version GitLab Community Edition v16.9.0 with the same configuration and it working fine. Maybe something different with GitLab Community Edition 14.0.12

alexeadem avatar Feb 20 '24 04:02 alexeadem