Visitar URL original
Can't create impersonation token from CLI · Issue #780 · python-gitlab/python-gitlab · GitHub
Skip to content

Can't create impersonation token from CLI #780

Description

@jgeorgeson

Description of the problem, including code/CLI snippet

Creation of user impersonation token fails from CLI with invalid scope error

$ gitlab -d -o json -g example user-impersonation-token create --user-id 168 --name test --scopes '["api"]'

It seems to be trying to pass the supplied value as a string instead of converting to an array (see the output in Actual Behavior). Have tried multiple variations of the scopes value such as api, [api], ["api"], "[api]", and "['api']".

Using curl like this

$ curl -X POST -H "Content-type: application/json" -H "PRIVATE-TOKEN: 123412341234" https://gitlab.example.com/api/v4/users/2/impersonation_tokens -d '{"name": "test", "scopes": ["api"]}'

Successfully creates the token.

Expected Behavior

Token is created.

Actual Behavior

send: b'POST /api/v4/users/2/impersonation_tokens HTTP/1.1\r\nHost: gitlab.example.com\r\nUser-Agent: python-requests/2.21.0\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nPRIVATE-TOKEN: 1234123412341234\r\nContent-type: application/json\r\nContent-Length: 55\r\n\r\n'
send: b'{"user_id": "2", "name": "test", "scopes": "[\'api\']"}'
reply: 'HTTP/1.1 400 Bad Request\r\n'
DEBUG:urllib3.connectionpool:https://gitlab.example.com:443 "POST /api/v4/users/2/impersonation_tokens HTTP/1.1" 400 29
Impossible to create object (400: scopes is invalid)
header: Server header: Date header: Content-Type header: Content-Length header: Connection header: Cache-Control header: Vary header: X-Content-Type-Options header: X-Frame-Options header: X-Request-Id header: X-Runtime 

Specifications

  • python-gitlab version: 1.8.0
  • API version you are using (v3/v4): v4
  • Gitlab server version (or gitlab.com): 11.4.4

Activity

  1. ruzickap commented on Jul 30, 2019

    @ruzickap

    Any news about it? I have the same issue...

  2. LonMcGregor commented on Aug 26, 2021

    @LonMcGregor

    I also seem to be getting a "scopes is invalid" error when trying to use gl.applications.create() and the scopes ['read_user', 'read_api']

    Python gitlab 2.10.0
    Api v4
    Gitlab 14.1.0-ee

  3. krzyslom commented on Sep 8, 2021

    @krzyslom

    edit: My bad, I've mixed up access token with deploy token. Latter doesn't allow the 'api' value. Proper ones work. It doesn't seem to be possible to create access token from CLI.

    original message:
    Hi
    I also struggle with a similar problem when using CLI - gitlab project-deploy-token create. Just like the author of the issue - I've tried multiple variations of the scopes value and using curl works.

    Also, inside Python session:
    this doesn't work

    project.access_token.create({"name": "somename", "scopes": "api")

    but this does

    project.access_token.create({"name": "somename", "scopes": ["api"])

    python 3.8.3
    python-gitlab 2.10.1
    API v4
    Gitlab 14.1.3

  4. locked as resolved and limited conversation to collaborators on Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions