Problem:
The npm client login has a limitation of [a-z0-9] characters for the username, whereas Nexus Repository 3 user tokens can include any characters that are available with Base64 encoding (https://en.wikipedia.org/wiki/Base64#Base64_table) .
Solution:
In order to use npm with user tokens, edit your .npmrc file and use basic authentication, adding your base64 encoded user token.
An example .npmrc:
registry = http://localhost:8081/nexus/content/groups/npm-group/
email=my@example.com
always-auth=true
_auth=NERZQU9iOUU6ZGQ3SkNkMUlvS2ZERko1WllSYmhOYXNFaGFMYzFNS1hDR2Uyay9wWEI0Tno=
In the above, the _auth value is the base64 encoded representation of your User Token “<userCode>:<passCode>”. There are two ways you can get this value:
Option 1:
Use one of the various encoding methods described here to encode your credentials.
Option 2:
In Nexus Repository version 3.7 and higher, 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.