gitlab-finder icon indicating copy to clipboard operation
gitlab-finder copied to clipboard

Always runs into HTTPError: Response code 401

Open bytehead opened this issue 1 year ago • 11 comments
trafficstars

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

bytehead avatar Jul 03 '24 11:07 bytehead

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

nis267 avatar Jul 25 '24 15:07 nis267

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

bytehead avatar Jul 29 '24 09:07 bytehead

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

ldbglobe avatar Jul 29 '24 11:07 ldbglobe

I'm gonna try it again 🙃

bytehead avatar Jul 29 '24 11:07 bytehead

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

Any ideas to debug?

bytehead avatar Jul 29 '24 11:07 bytehead

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

ldbglobe avatar Jul 29 '24 14:07 ldbglobe

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

nis267 avatar Jul 30 '24 13:07 nis267

@nis267 With an organization?

# Group ID to search in
# default search in all groups
GROUP_ID=

bytehead avatar Jul 30 '24 13:07 bytehead

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

bytehead avatar Jul 30 '24 13:07 bytehead

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

nis267 avatar Jul 30 '24 13:07 nis267

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=

bytehead avatar Jul 30 '24 13:07 bytehead