一些组织将他们自己的包托管在需要身份验证才能访问的私有包注册表上。如果您是这类组织的员工或客户,则必须使用 npm 身份验证来配置一个范围注册表。要进行设置,请获取 npm 身份验证令牌,然后将该令牌添加到您的用户配置文件中。
对于各注册表提供程序,创建和访问 npm 身份验证令牌的过程均不同。例如,JFrog 的 Bintray 和 Artifactory 代码仓库管理器使用不同的过程从 npm 生成身份验证令牌。这是典型过程的示例,但您需要遵循特定包注册表提供程序为您的范围注册表推荐的过程。
要从 npm 获取身份验证令牌:
在您的机器上本地安装 npm。
从终端输入以下命令以登录注册表:
$ npm login --registry <registry url>
找到并打开生成的 .npmrc 文件。
找到 _authToken
或 _auth
条目并复制其值(请参见下面的示例)。
根据注册表,令牌字符串可以是 GUID、令牌或专有格式的字符串。
这是一个包含 _authToken
属性的 .npmrc
文件示例:
registry=https://example.com:1234/mylocation/
//example.com:1234/mylocation/:_authToken=<AUTH TOKEN>
这是一个包含 _auth
属性的 .npmrc
文件示例:
registry=https://example.com:1234/mylocation
_auth=<AUTH TOKEN>
email=<EMAIL>
always-auth=true
使用 npmAuth
配置模式,将需要身份验证的每个范围注册表的令牌信息存储在 .upmconfig.toml
用户配置文件。将此信息保存到配置文件后,Package Manager 将针对向文件中的每个注册表发出的每个请求提供您的身份验证信息。
按照以下说明将您的身份验证信息添加到用户配置文件中:
找到 .upmconfig.toml
用户配置文件。如果该文件尚不存在,请创建一个空文本文件。
使用一种模式格式化您的身份验证信息,具体取决于您使用的是 Bearer(基于令牌)还是 Basic(Base64 加密)身份验证机制:
[npmAuth."<REGISTRY URL>"]
<TOKEN-PROPERTY> = "<TOKEN-VALUE>"
email = "<EMAIL>"
alwaysAuth = <BOOLEAN>
下表阐明了如何指定配置文件值:
条目 | 描述: |
---|---|
[npmAuth."<REGISTRY URL>"] |
必需。注册表 URL。例如,[npmAuth."https://example.com:8081/mylocation"] 。 |
<TOKEN-PROPERTY> = "<TOKEN-VALUE>" |
必需。从 npm 注册表生成的身份验证令牌。可以是 GUID、令牌或专有格式的字符串。例如,可以是 token = "<AUTH TOKEN>" (Bearer) 或 _auth = "<BASE64 TOKEN>" (Basic)。 |
可选。与注册表中用户电子邮件匹配的用户的电子邮件地址。 | |
alwaysAuth | 可选。如果包元数据和 tarball 不在同一服务器上,则设置为 true。通常,您可以从生成的 .npmrc 文件复制该值。 |
[npmAuth."http://localhost:8081/myrepository/mylocation"]
token = "NpmToken.2348c7ea-6f86-3dbe-86b6-f257e86569a8"
alwaysAuth = true
[npmAuth."http://localhost:4873"]
token = "eaJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyZWFsX2dyb3VwcyI6WyJwYXNjYWxsIl0sIm5hbWUiOiJwYXNjYWxsIiwiZ3JvdXBzIjpbInBhc2NhbGwiLCIkYWxsIiwiJGF1dGhlbnRpY2F0ZWQiLCJAYWxsIiwiQGF1dGhlbnRpY2F0ZWQiLCJhbGwiLCJwYXNjYWxsIl0sImlhdCI6MTU3NDY4ODQ5MCwibmJmIjoxNTc0Njg4NDkxLCJleHAiOjE1Nzk4NzI0OTB9.qF8_0ue1ppraWLkReT06AMG6R7RZuDiV2XinxMkdSo0"
[npmAuth."https://api.bintray.example/npm/mycompany/myregistry"]
token = "aGFzY2FsbDo4ZWIwNTM5NzBjNTI3OTIwYjQ4MDVkYzY2YWEzNmQxOTkyNDYzZjky"
email = "username@example.com"
alwaysAuth = true
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.