Comments (12)
@trivialkettle I think GitLab no longer supports basic authentication for normal API usage, only specific endpoints like some types of packages.
Are you able to use basic authentication with curl for the endpoint you show above?
from python-gitlab.
curl -vv --header "Authorization: Basic <base64>" "https://gitlab.company.com/api/v4/user"
Returns 401
Though
curl -vv --header "Authorization: Basic <base64>" "https://gitlab.company.com/api/v4/projects"
returns 200 and an empty list.
from python-gitlab.
@trivialkettle is this then consistent with the behavior you see in python-gitlab? i.e. if you skip gl.auth()
which calls the user endpoint, do you get an empty response as well?
from python-gitlab.
@nejch
Yes this is consistent.
>>> client = gitlab.Gitlab(url="gitlab.company.com")
>>> client.projects.list()
[]
from python-gitlab.
Thanks @trivialkettle in that case I think there's not much we can do here, maybe we can document the upstream limitation, but I see they have a lot of other similar issues related to inconsistencies in auth and endpoints (see e.g. https://gitlab.com/gitlab-org/gitlab/-/issues/296041). If you like you could also file an issue upstream to see if this is intentional 🙇
from python-gitlab.
@nejch
A workaround could be to avoid basic auth from requests
and use e.g. Authentication: Bearer <token>
as shown in https://docs.gitlab.com/ee/api/rest/#authentication
from python-gitlab.
Hmm, technically we could do this but IMO it deviates from the requests
behavior in https://requests.readthedocs.io/en/latest/user/authentication/#netrc-authentication (as well as others supporting netrc such as httpx
& co.), and I feel like we might be relying on undocumented GitLab behavior as well.
Would https://docs.python.org/3/library/netrc.html be an alternative maybe?
from python-gitlab.
Authentication: Bearer <token>
is documented: https://docs.gitlab.com/ee/api/rest/#personalprojectgroup-access-tokens
curl --header "Authorization: Bearer <your_access_token>" "https://gitlab.example.com/api/v4/projects"
So I don't see how we could rely on undocumented behavior.
deviates from the
requests
behavior
Yes, thats why I would not so happy with that.
Would https://docs.python.org/3/library/netrc.html be an alternative maybe?
For API usage yes, but I would like to use the CLI with .netrc
support.
from python-gitlab.
@nejch Yes this is consistent.
>>> client = gitlab.Gitlab(url="gitlab.company.com") >>> client.projects.list() []
To be clear, the behavior is consistent, but the result is wrong. With Authentication: Bearer <token>
I get all my projects,
from python-gitlab.
@nejch Yes this is consistent.
>>> client = gitlab.Gitlab(url="gitlab.company.com") >>> client.projects.list() []
To be clear, the behavior is consistent, but the result is wrong. With
Authentication: Bearer <token>
I get all my projects,
@trivialkettle I would consider this an upstream issue (/user
accepts bearer token auth but not basic auth, whereas other endpoints do, but return different results -EDIT seems like /projects
actually works without authentication, so maybe it's not really accepted anyway).We just want to avoid making workarounds in the client for bugs in the API itself, would be best to fix it upstream instead.
But I see what you mean with the CLI, if we're forcing unwanted API calls then that's wrong, but I need to check if that's always the behavior.
from python-gitlab.
This issue was marked stale because it has been open 60 days with no activity. Please remove the stale label or comment on this issue. Otherwise, it will be closed in 15 days.
from python-gitlab.
With #2792 we can now skip the initial /user
call for auth()
, so if people want to use the CLI with .netrc
for those endpoints that potentially support it, this should be possible now. But as I said whether GitLab supports basic auth (which is what netrc is for), that is up to them to decide. Mainly this is used for packages.
I'll close this but feel free to reopen if you disagree.
from python-gitlab.
Related Issues (20)
- Support group-level service-accounts
- Add group.shared_with_groups.list() HOT 2
- const module not exposed HOT 1
- Missing content Class Variable in ProjectFile Class HOT 3
- Improve documentation on usage of Docker image directly within Gitlab CI HOT 1
- ProjectMergeRequestApprovalManager.set_approvers cannot handle too many approval rules
- Bug: List all projects of current user returns empty list HOT 1
- In CommitManager, using the path filter breaks the endpoint call HOT 3
- Feature: add `pages` support in `project`
- update CI/CD Variables with a specific env
- personal_access_tokens.rotate(<ID>) 'dict' object has no attribute 'token' HOT 3
- get_id() retruns name of label
- project.commits.list(path=some/path.txt) fails because "path" param is used to override path in ListMixin.list HOT 2
- Introduce a global setting to always get all element from `list()` calls HOT 1
- `path` argument of "List repository commits" is overriden
- Feature: Retrieve the job that generated a job token from /job api call
- Cannot update/patch protected branch allowed_to_push/push_access_levels state HOT 1
- How do I differentiate between "405 Method Not Allowed" due to the source branch not being updated or due to conflicts? HOT 1
- Memory increase while using the client HOT 3
- API for get and add MR to merge train is missing HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-gitlab.