Using User Token’s with NPM

Problem:

The npm cli login has a limitation of lower case characters and numbers for the username whereas Nexus Repository Manager User Token’s include any characters that are available with Base64 encoding as described in https://en.wikipedia.org/wiki/Base64#Base64_table.

 

Solution:

In order to use npm with User Token’s a simple solution is to edit your .npmrc file and use Basic Authentication, adding your base64 encoded User Token. This is described in more detail here; below is a short example:

 

An example .npmrc:

registry = http://localhost:8081/nexus/content/groups/npm-group/
email=my@example.com
always-auth=true
_auth=NERZQU9iOUU6ZGQ3SkNkMUlvS2ZERko1WllSYmhOYXNFaGFMYzFNS1hDR2Uyay9wWEI0Tno=

 

where _auth value is the base64 encoded representation of your User Token “<userCode>:<passCode>”.

 

Option 1:

To generate the base64 encoded string you can do the following:

echo -n '<userCode>:<passCode>' | openssl base64

 

Option 2:

From Nexus Repository Manager version 3.7 onwards, the User Token details view now displays the generated base64 encoded string that you can copy and paste into your .npmrc directly. As an example, see the screenshot below:

usertoke.png

 

Have more questions? Submit a request

0 Comments

Article is closed for comments.
Powered by Zendesk