Hello Package Manager users!
Starting from Unity 2019.3.4f1, you’ll be able to configure NPM authentication for your scoped registries. This is a feature that was heavily requested by our enterprise customers.
Attention: Before we explain how to configure your authentication token, I just want to warn we are making this feature available in its MVP form to unblock some of you. That means, a couple of manual operations are required (i.e. not really user-friendly). The end goal is to expose a login UI in the Hub. Users will only have to enter their credentials and the rest would be taken care of.
Below, I copied the internal draft documentation sent to our technical writer to be added to the Unity user manual. Please note this will be greatly re-formatted and improved when finalized.
Introduction
The introduction of scoped registries enabled enterprise users to share their own custom packages inside their studio. For most studios and companies, anonymous access within a local network is sufficient to fulfill their security requirements. Nevertheless, some users want more control and enable authentication on a user base. Most off-the-shelve or open-source registry solutions support npm authentication through a persistent token. This document explains how to configure UPM to enable this feature.
Feature availability
The feature was introduced in Unity 2019.3.4f1 and 2020.1.0a25.
Manual login
Users will need to fetch their authentication token via npm command-line interface and manually copy and paste the token in UPM global configuration file.
1) Fetch the npm authentication token
Warning: Inconsistent login flow across vendors
Registry vendors may have different login flow. The login procedure described below is the official npm login flow. Some vendors, like JFrog (Bintray and Artifactory), require different steps to generate the authentication token. Please, consult their respective documentation to make sure you go through the proper process to fetch the token.
- Install npm locally on your machine.
- Login to the registry using the npm login command-line. In a terminal type this command:
npm login --registry <registry url>
- Locate the generated .npmrc file.
- Open the .npmrc file. Extract the token (look for the AUTH_TOKEN label in the examples below. Depending on the registry, the token string will be different (guid, token, or a proprietary formatted string).
Here are some examples of .npmrc files:
.npmrc with _authToken attribute
registry=https://registry.com:1234/pathname/
//registry.com:1234/pathname/:_authToken=<AUTH TOKEN>
.npmrc with _auth attribute (Base64 encoded)
registry=https://registry.com:1234/pathname
_auth=<AUTH TOKEN>
email=<EMAIL>
always-auth=true
2) Create a Unity Package Manager user configuration file
This section explains how to set up UPM configuration so every request made to the registry includes proper authentication information.
2.1) Unity Package Manager user configuration file location
Locate .upmconfig.toml in your home directory:
Windows: %USERPROFILE%/.upmconfig.toml (Usually %SystemDrive%\Users<your username>/.upmconfig.toml)
Windows (System user) : %ALLUSERSPROFILE%Unity/config/ServiceAccounts/.upmconfig.toml
MacOS and Linux: ~/.upmconfig.toml (usually /Users//.upmconfig.toml)
If the file does not already exist, create one.
2.2) User configuration file schema
2.2.1 Schema
This is the schema for the configuration npmAuth attribute:
Token based authentication (Bearer)
[npmAuth."<REGISTRY URL>"]
token = "<AUTH TOKEN _authToken in .npmrc)>"
email = "<EMAIL>"
alwaysAuth = <BOOLEAN>
Base64 authentication (Basic)
[npmAuth."<REGISTRY URL>"]
_auth = "<BASE64 ENCODED TOKEN (_auth in .npmrc)>"
email = "<EMAIL>"
alwaysAuth = <BOOLEAN>
2.2.1 Details
registry-url (required) : Url for the registry (ex: https://my.registry:8081/some/path) .
token or _auth (required): The authentication token generated from login to the npm registry. See the previous section to understand how to generate and fetch the token.
email (optional): User email.
alwaysAuth (optional): Set to true if the package metadata and tarballs and not located on the same server. Typically, you’ll copy the value from the generated .npmrc if present (see the previous section).
2.2.2 Example
[npmAuth."http://localhost:8081/repository/test"]
token = "NpmToken.2348c7ea-6f86-3dbe-86b6-f257e86569a8"
alwaysAuth = true
[npmAuth."http://localhost:4873"]
token = "eaJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyZWFsX2dyb3VwcyI6WyJwYXNjYWxsIl0sIm5hbWUiOiJwYXNjYWxsIiwiZ3JvdXBzIjpbInBhc2NhbGwiLCIkYWxsIiwiJGF1dGhlbnRpY2F0ZWQiLCJAYWxsIiwiQGF1dGhlbnRpY2F0ZWQiLCJhbGwiLCJwYXNjYWxsIl0sImlhdCI6MTU3NDY4ODQ5MCwibmJmIjoxNTc0Njg4NDkxLCJleHAiOjE1Nzk4NzI0OTB9.qF8_0ue1ppraWLkReT06AMG6R7RZuDiV2XinxMkdSo0"
"
[npmAuth."https://api.bintray.com/npm/joe-company/my-registry"]
token = "aGFzY2FsbDo4ZWIwNTM5NzBjNTI3OTIwYjQ4MDVkYzY2YWEzNmQxOTkyNDYzZjky"
email = "joe@company.com"
alwaysAuth = true
[npmAuth."https://base64.registry.com"]
_auth = "aGFzY2FsbDo4ZWIwNTM5NzBjNTI3OTIwYjQ4MDVkYzY2YWEzNmQxOTkyNDYzZjky"
email = "joe@company.com"
alwaysAuth = true
Again, really sorry about the crude/raw form of this feature for the moment but I hope this will still be helpful for some of you.
Pascal