Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Authorization Bearer header instead of PAT on demand #877

Open
mfriedenhagen opened this issue Jul 28, 2023 · 2 comments
Open

Use Authorization Bearer header instead of PAT on demand #877

mfriedenhagen opened this issue Jul 28, 2023 · 2 comments

Comments

@mfriedenhagen
Copy link

  • PATs in our company instance are expired after one day by an automated process.
  • Our company instance requires a daily MFA login via SSO.
  • We implemented https://github.com/hickford/git-credential-oauth to gather tokens for authentication. The oauth application in GitLab is able to issue token with scope api as well.
  • This works fine with all standard git operations like pull orpush.
  • I tried to use the token with lab. However I get a 401 when setting the oauth bearer token as LAB_CORE_TOKEN.
  • That is probably because lab does use the header PRIVATE-TOKEN which does only accept a GitLab PAT.
  • When I call the API via curl and use the oauth token as bearer token in the Authorization` header, this does succeed.
  • The oauth token has 64 characters and matches [a-f0-9]{64} so it should be quite easy to differentiate a PAT and this kind of token.
@mfriedenhagen mfriedenhagen changed the title Use Authorization Bearer header on demand Use Authorization Bearer header instead of PAT on demand Jul 28, 2023
@prarit
Copy link
Collaborator

prarit commented Aug 14, 2023

Interesting. I'm trying to play around with oath2 but :( sadly cannot figure a valid URI on gitlab. Let me try a few things to see if I can get some test code to you.

@prarit
Copy link
Collaborator

prarit commented Aug 14, 2023

@mfriedenhagen, can you try the following quick hack and let me know if this works?

diff --git a/internal/gitlab/gitlab.go b/internal/gitlab/gitlab.go
index 65cfd8849631..3e6a44dd7f19 100644
--- a/internal/gitlab/gitlab.go
+++ b/internal/gitlab/gitlab.go
@@ -97,7 +97,7 @@ func Init(_host, _user, _token string, allowInsecure bool) {
                },
        }
 
-       lab, _ = gitlab.NewClient(token, gitlab.WithHTTPClient(httpClient), gitlab.WithBaseURL(host+"/api/v4"), gitlab.WithCustomLeveledLogger(log))
+       lab, _ = gitlab.NewBasicAuthClient(_user, token, gitlab.WithHTTPClient(httpClient), gitlab.WithBaseURL(host+"/api/v4"), gitlab.WithCustomLeveledLogger(log))
 }
 
 // InitWithCustomCA open the HTTP client using a custom CA file (a self signed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants