npm ERR! Unable to authenticate, need: Basic realm="Artifactory Realm"

Najeeb picture Najeeb · Aug 10, 2021 · Viewed 23.7k times · Source

I tried to run the command:

npm install -g @angular/[email protected]

but I have got the following error:

npm ERR! code E401
npm ERR! Unable to authenticate, need: Basic realm="Artifactory Realm"

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/xxxx/.npm/_logs/2021-08-10T19_33_12_063Z-debug.log

note: node js and npm worked fine.

I have followed the instructions in Artifactory to solve this issue using the command:

npm config set registry https://artifactory.......com/artifactory/api/npm/xxxx/

as I have paste the following into the ~/.npmrc file :

_auth = fhgf......ghgj==
email = [email protected]
always-auth = true

I have also tried using npm login, but I have got the below err and couldn’t continue:

npm login
Username: [email protected]
npm WARN Name may not contain non-url-safe chars 
Username: ([email protected])
Username: ([email protected])
Username: ([email protected])
Username: ([email protected])

How can i solve this issue?

Answer

soccer7 picture soccer7 · Dec 17, 2021

Update Dec, 2021

Artifactory moved to support APIKEY only. If your old _auth was base64 encoding of username:password or username:encrypted_password then both are unacceptable now. You must use APIKEY in place of these.

So, the supported _auth now becomes:

_auth: APIKEY

But ironically, even this didn't work in some cases.

Following seemed to be more reliable:

  1. You need to get base64 string of your username:APIKEY. You can get base64 by running following command in PowerShell

[System.Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes("username:APIKEY"))

  1. Whatever is the output, use that in _auth variable of your .npmrc file (located in %userprofile%\.npmrc)

So, the final file looks like following:

registry=<URL>
_auth = <Base64 of username:APIKEY>
email = [email protected]
always-auth = true