diff --git a/guide/authentication/index.md b/guide/authentication/index.md index 0a5ca4b..6301f74 100644 --- a/guide/authentication/index.md +++ b/guide/authentication/index.md @@ -1,40 +1,39 @@ --- -title: Authentication +title: 認証 --- -There are two options for authenticating with the API. The basic choice boils -down to: +このAPIにおいては、認証には2つの選択肢があり、基本的に以下のように選びましょう。 -* Are you a plugin/theme running on the site? Use **cookie authentication** -* Are you a desktop/web/mobile client accessing the site externally? Use - **OAuth authentication** +* そのサイトで有効化されたテーマやプラグインから利用するのであれば **クッキー認証** +* デスクトップアプリ、ウェブアプリ、モバイルアプリなどのサイトの外からアクセスするクライアントから API を利用するのであれば **OAuth 認証** - -Cookie Authentication +クッキー認証 --------------------- -Cookie authentication is the basic authentication method included with -WordPress. When you log in to your dashboard, this sets up the cookies correctly -for you, so plugin and theme developers need only to have a logged-in user. - -However, the REST API includes a technique called [nonces][] to avoid [CSRF][] issues. -This prevents other sites from forcing you to perform actions without explicitly -intending to do so. This requires slightly special handling for the API. +クッキー認証は、WordPress に実装された基礎的な認証です。 +管理画面にログインするときには、このクッキー認証が利用されており、ログインするユーザーのクッキーが正しく発行されています。 +したがって、プラグインやテーマ開発者が必要とするのはログインしているユーザーのみとなります。 -For developers using the built-in Javascript API, this is handled automatically -for you. This is the recommended way to use the API for plugins and themes. -Custom data models can extend `wp.api.models.Base` to ensure this is sent -correctly for any custom requests. +しかしながら、REST API では [CSRF][] の問題を解決するために [nonces][] と呼ばれる技術を利用しています。 +そのおかげで、他のサイトを経由して、あなたが明示的に意図していない行動をとってしまうのを防いでいるのですが、 +同時に、API 利用のために少し特殊な操作が必要になります。 +プラグインやテーマの作者がビルトイン Javascript API を利用する場合には、この処理は自動的に行われます(推奨)。 +独自のデータモデルからアクセスする場合には、 `wp.api.models.Base` を継承することで、 +あらゆるカスタムリクエストで nonce がきちんと送信されることが保証されます。 -For developers making manual Ajax requests, the nonce will need to be passed -with each request. The API uses nonces with the action set to `wp_rest`. These -can then be passed to the API via the `_wpnonce` data parameter (either POST data or in the query for GET requests), or via the `X-WP-Nonce` header. +マニュアルで Ajax リクエストを送る場合、nonce は各リクエストで毎回送信する必要があります。 +送信された nonce は `wp_rest` にセットされたアクションと一緒に利用されます。 +API への nonce の受け渡しは、POST のデータや GET のクエリの `_wpnonce` パラメータ、 +あるいは`X-WP-Nonce` ヘッダーにセットして行います。 -Note: Until recently, most software had spotty support for `DELETE` requests. For instance, PHP doesn't transform the request body of a `DELETE` request into a super global. As such, supplying the nonce as a header is the most reliable approach. +Note: Until recently, most software had spotty support for `DELETE` requests. For instance, PHP doesn't transform the request body of a `DELETE` request into a super global. 従って、ヘッダーとして nonce を供給するやり方が最も信頼できるアプローチとなります。 -It is important to keep in mind that this authentication method relies on WordPress cookies. As a result this method is only applicable when the REST API is used inside of WordPress and the current user is logged in. In addition, the current user must have the appropriate capability to perform the action being performed. +この認証は WordPress のクッキーに依存しているということは覚えておきましょう。 +このクッキー認証が利用できるのは、REST API が WordPress の内部から使われていて、 +かつ、ユーザーがログインしている時のみであるということです。 +さらに、そのログインユーザーが、実行しようとしているアクションに必要な権限を与えられているということも条件となります。 -As an example, this is how the built-in Javascript client creates the nonce: +以下は、ビルトインの Javascript クライアントが nonce を生成する例です。 ```php