ldbglobe / gitlab-finder

NodeJs CLI tools to search keywords in find across all your project
28 stars 6 forks source link

Always runs into HTTPError: Response code 401 #5

Open bytehead opened 4 months ago

bytehead commented 4 months ago

Hi there πŸ‘‹πŸΌ

I followed the README but somehow my token is always shown as invalid.

I tried with other libraries to make requests to the API and the token is considered valid there. Don't know what I'm missing here? Any ideas? Is the underlaying library broken (gitbeaker)?


➜  gitlab-finder ~/gitlab-finder git:(master) βœ— yarn search
yarn run v1.22.19
warning ../../../package.json: No license field
$ node src/search.js
node:internal/process/promises:289
            triggerUncaughtException(err, true /* fromPromise */);
            ^

HTTPError: Response code 401 (Unauthorized)
    at Request.<anonymous> (/gitlab-finder/node_modules/got/dist/source/as-promise/index.js:118:42)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  code: 'ERR_NON_2XX_3XX_RESPONSE',
  timings: {
    start: 1720005885242,
    socket: 1720005885243,
    lookup: 1720005885254,
    connect: 1720005885267,
    secureConnect: 1720005885278,
    upload: 1720005885278,
    response: 1720005885441,
    end: 1720005885443,
    error: undefined,
    abort: undefined,
    phases: {
      wait: 1,
      dns: 11,
      tcp: 13,
      tls: 11,
      request: 0,
      firstByte: 163,
      download: 2,
      total: 201
    }
  },
  description: 'invalid_token'
}

Node.js v20.12.1
nis267 commented 3 months ago

For me it works fine. Maybe you added the wrong gitlab host in the .env? @bytehead

bytehead commented 3 months ago

ok, a little hope at least :) but no, the gitlab host seems to be correct, https://gitlab.com.

ldbglobe commented 3 months ago

Hi @bytehead To replicate your issue, I just set in my .env a wrong personnal token Maybe you just have to generate a new one https://gitlab.com/-/user_settings/personal_access_tokens

image

I also run into some several minor bug so I just push an update to upgrade the GitBeaker library

bytehead commented 3 months ago

I'm gonna try it again πŸ™ƒ

bytehead commented 3 months ago

I don't get it πŸ˜… Just regenerated a token (even) with api scope - still getting GitbeakerRequestError: Unauthorized.

Any ideas to debug?

ldbglobe commented 3 months ago

@bytehead another dependencies update, but I still have no clue about your error and how to replicate it.

nis267 commented 3 months ago

I created an account on https://gitlab.com/ and even there it works for me with a new generated token.

bytehead commented 3 months ago

@nis267 With an organization?

# Group ID to search in
# default search in all groups
GROUP_ID=
bytehead commented 3 months ago

In my case it gives me this GitbeakerRequestError: Unauthorized error in both cases, with a GROUP_ID and without. 😞

nis267 commented 3 months ago

My env looks like this with my token hidden with x's

GITLAB_HOST=https://gitlab.com GITLAB_TOKEN=glpat-xxxxxxxxxxxxxxxxxxx SEARCH_DELAY=6000 SEARCH_FILE_PATTERN=* SEARCH_KEYWORD=test GROUP_ID=

And are you sure that you don't have gitlab self hosted? Then the host is different than https://gitlab.com

bytehead commented 3 months ago

here is my .env:

GITLAB_HOST=https://gitlab.com
GITLAB_TOKEN=glpat-xxx
# pause time in ms between search api call (6000 is recommanded on official Gitlab instance)
SEARCH_DELAY=6000
# File pattern filter (eg. *.php)
SEARCH_FILE_PATTERN=*
# string to find
SEARCH_KEYWORD=test
# Group ID to search in
# default search in all groups
GROUP_ID=