Development on some LabKey modules requires npmrc authentication to obtain resources from Artifactory. Npmrc files encapsulate login credentials so that they don't need to be included in plain text in other applications. This topic shows you how to set up a .npmrc authentication file on your development machine.
Get Your Artifactory Identity Token
- If you have already generated an Identity Token with Artifactory, you will likely have captured that token as the artifactory_password property in the .gradle/gradle.properties file in your Home directory. (Note that an Identity Token is different from an API Key. If you have a value set for artifactory_password but have not gone through the process of generating an Identity Token, you will need to do that first.)
- If you have not captured the Identity Token in a gradle.properties file, you will likely need to generate a new one. Once generated, the token is no longer visible within the Artifactory UI.
Encode the Identity Token
The password you need to include in the .npmrc file is actually NOT your Identity Token. It is, instead, the base-64-encoded version of your Identity Token.
- Use the following curl request to generate the authentication snippet for your .npmrc file:
curl -u <USER>:<ARTIFACTORY_IDENTITY_TOKEN> https://labkey.jfrog.io/artifactory/api/npm/auth
Where <USER> is your Artifactory login (likely your GitHub login) and <ARTIFACTORY_IDENTITY_TOKEN> is the unencoded version.
- You can also use your favorite base-64 encoder to generate the base-64-encoded version of your API key (on a Mac, base64 on command line works just fine) and then substitute that in your .npmrc file. The curl method is preferred, however, because it will give much better feedback than npm itself if there are any problems authenticating. Note that if the authentication snippet returned above contains port numbers for the Artifactory server (e.g., https://labkey.jfrog.io:443/artifactory/api/npm/libs-client/), these port numbers should be removed.
Add the .npmrc File
- Add (or edit) an .npmrc file in your home directory.
- On Linux or MacOS: ~/.npmrc
- On Windows: %USERPROFILE%\.npmrc (Like C:\Users\Steve\.npmrc.)
- Handy tip: in Windows Explorer create a file named ".npmrc.", and Windows will strip off the trailing dot, to create a .npmrc file.
- Add the following snippet, modified with your username, encoded Artifactory Access Token, and email.
- The snippet below is scoped to @labkey. Modify if necessary for your requirements.
@labkey:registry=https://labkey.jfrog.io/artifactory/api/npm/libs-client/
//labkey.jfrog.io/artifactory/api/npm/libs-client/:_auth=<BASE64_ENCODED_TOKEN>
//labkey.jfrog.io/artifactory/api/npm/libs-client/:username=<USERNAME>
//labkey.jfrog.io/artifactory/api/npm/libs-client/:email=youremail@email.com
Note, you can remove the line:
//labkey.jfrog.io/artifactory/api/npm/libs-client/:always-auth=true
as this is no longer supported in versions of npm 6+.
Update your .npmrc File to use Identity Token authentication instead of API Key
Artifactory is
deprecating the use of the API key, and is scheduled to stop supporting it in Q1 of 2024. To assure continued operation of your build, you will want to switch from using the API Key to an Identity Token. This can be accomplished as follows:
1.
Generate an identity token, capturing it in the .gradle/gradle.properties file in your home directory.
2. Use the
curl command from above to generate the encoded version of the identity token
3. Replace this line:
//labkey.jfrog.io/artifactory/api/npm/libs-client/:_password=<BASE64_ENCODED_API_KEY>
with this line:
//labkey.jfrog.io/artifactory/api/npm/libs-client/:_auth=<BASE64_ENCODED_TOKEN>
Note the change from _password to _auth here.
Once you have tested that publishing and/or pulling NPM artifacts works with the new token, you can revoke your existing API key from you profile page in Artifactory, just to assure you aren't accidentally using it in one way or another.