NPM registry unauthorized error using personal token

I’ve followed the tutorial found here:
https://docs.gitlab.com/ee/user/project/packages/npm_registry.html

But I keep getting Unauthorized 401 errors. I’m using a personal token that has all the scopes available.

I’ve tried to do it both locally and from within gitlab with the same luck.
Does anyone have any suggestions?

2 Likes

I’ve got the same issue.

Update 1: I managed to intercept the network request to Gitlab that npm sends. It does not have the Authentication header despite <repository>:_authToken configured in .npmrc as described in https://docs.gitlab.com/ee/user/project/packages/npm_registry.html#authenticating-with-an-oauth-token and https://docs.npmjs.com/using-private-packages-in-a-ci-cd-workflow.

Update 2: To force npm publish to send the Authorization header, add always-auth=true to your .npmrc: https://npm.community/t/authorization-header-is-not-sent-when-we-give-npm-install-with-verdaccio-in-npm-v6-9-0-but-it-works-with-npm-v3-10-10/8770/2.

Unfortunately, even though npm publish now correctly sends Authorization: Bearer abc where abc is my personal token, I am still getting 401 Unauthorized.

I am seeing the same issue on my end trying to publish a package to the NPM registry. Has anyone found the solution to this?

I’m seeing this on one of my projects. Can’t figure it out. Anyone come up with something?

I wonder if it’s related to my issue. I’m experiencing the same but with nuGet repository using the DotNet CLI to push packages with an API key with apiand write scopes. I opened a question at stack overflow but so far no answer.

Does anybody have any answer for the issue with npm? Maybe I’d help with my nuget issue

@diegosaswYou are getting a 401 error when you try and publish a NuGet package? The access token is set to API? Please feel free to open an issue and assign it to me.

1 Like

@trizzi, yes.
I opened the following issue: https://gitlab.com/gitlab-com/support-forum/issues/5238
Not sure whether I have permissions to assign tickets. I hope it’s the right place!
Thanks

Hi earshinov, in my case it was the path to allocate the NPM package, you have to put package on an unique name project and you must have permissions over that project and path.

In step number 3 you can see that the group and project must be the same with the name of your package.
3. Create project in GDK with group name foo and project name bar