組織によっては、アクセスに認証が必要なプライベートパッケージレジストリで独自のパッケージをホストしている場合があります。このような組織の従業員や顧客の場合、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 | 任意です。パッケージのメタデータと .tgz ファイルが同じサーバーに置かれていない場合、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.