2
2
title : 認証
3
3
---
4
4
5
- <<<<<<< HEAD
6
- このAPIにおいては、認証には2つの選択肢があり、基本的に以下のように選びましょう。
5
+ このAPIにおいては、認証には幾つかの選択肢があり、基本的に以下のように選びましょう。
7
6
8
7
* そのサイトで有効化されたテーマやプラグインから利用するのであれば ** クッキー認証**
9
- * デスクトップアプリ、ウェブアプリ、モバイルアプリなどのサイトの外からアクセスするクライアントから API を利用するのであれば ** OAuth 認証**
10
- =======
11
- There are several options for authenticating with the API. The basic choice boils
12
- down to:
13
-
14
- * Are you a plugin/theme running on the site? Use ** cookie authentication**
15
- * Are you a desktop/web/mobile client accessing the site externally? Use
16
- ** OAuth authentication** , ** application passwords** , or ** basic authentication** .
17
- >>>>>>> upstream/gh-pages
8
+ * デスクトップアプリ、ウェブアプリ、モバイルアプリなどのサイトの外からアクセスするクライアントから API を利用するのであれば ** OAuth 認証** , ** アプリケーションパスワード** または ** ベーシック認証**
18
9
19
10
クッキー認証
20
11
---------------------
@@ -30,8 +21,7 @@ down to:
30
21
独自のデータモデルからアクセスする場合には、 ` wp.api.models.Base ` を継承することで、
31
22
あらゆるカスタムリクエストで nonce がきちんと送信されることが保証されます。
32
23
33
- <<<<<<< HEAD
34
- マニュアルで Ajax リクエストを送る場合、nonce は各リクエストで毎回送信する必要があります。
24
+ マニュアルで Ajax リクエストを送る場合、nonce は各リクエストで毎回送信する必要があります。
35
25
送信された nonce は ` wp_rest ` にセットされたアクションと一緒に利用されます。
36
26
API への nonce の受け渡しは、POST のデータや GET のクエリの ` _wpnonce ` パラメータ、
37
27
あるいは` X-WP-Nonce ` ヘッダーにセットして行います。
@@ -42,21 +32,6 @@ Note: Until recently, most software had spotty support for `DELETE` requests. Fo
42
32
このクッキー認証が利用できるのは、REST API が WordPress の内部から使われていて、
43
33
かつ、ユーザーがログインしている時のみであるということです。
44
34
さらに、そのログインユーザーが、実行しようとしているアクションに必要な権限を与えられているということも条件となります。
45
- =======
46
- For developers making manual Ajax requests, the nonce will need to be passed
47
- with each request. The API uses nonces with the action set to ` wp_rest ` . These
48
- can then be passed to the API via the ` _wpnonce ` data parameter (either POST
49
- data or in the query for GET requests), or via the ` X-WP-Nonce ` header.
50
-
51
- Note: Until recently, most software had spotty support for ` DELETE ` requests. For
52
- instance, PHP doesn't transform the request body of a ` DELETE ` request into a super
53
- global. As such, supplying the nonce as a header is the most reliable approach.
54
-
55
- It is important to keep in mind that this authentication method relies on WordPress
56
- cookies. As a result this method is only applicable when the REST API is used inside
57
- of WordPress and the current user is logged in. In addition, the current user must
58
- have the appropriate capability to perform the action being performed.
59
- >>>>>>> upstream/gh-pages
60
35
61
36
以下は、ビルトインの Javascript クライアントが nonce を生成する例です。
62
37
@@ -105,14 +80,9 @@ OAuth 認証でも、ユーザーは通常の WordPress ログイン画面を通
105
80
その後、自身に代わって処理を行うクライアントを認証します。
106
81
クライアントには、OAuth トークンが発行され、API へのアクセスが許可されます。このアクセス権はユーザー側からいつでも取り消すことができます。
107
82
108
- <<<<<<< HEAD
109
83
OAuth 認証は、[ OAuth 1.0a specification] [ oauth ] (published as
110
84
RFC5849) を利用しており、[ OAuth plugin] [ oauth-plugin ] がサイトで
111
- 有効化されていることが必要です(このプラグインは将来的にコアにマージされます)。
112
- =======
113
- OAuth authentication uses the [ OAuth 1.0a specification] [ oauth ] (published as
114
- RFC5849) and requires installing the [ OAuth plugin] [ oauth-plugin ] on the site.
115
- >>>>>>> upstream/gh-pages
85
+ 有効化されていることが必要です。
116
86
117
87
WP API と OAuth サーバー用のプラグインを有効化したら、コンシューマを作成しましょう。
118
88
コンシューマは、アプリケーションの識別子であり、サイトとリンクするために必要な key と secret からなります。
@@ -137,47 +107,25 @@ Secret: LnUdIsyhPFnURkatekRIAUfYV7nmP4iF3AVxkS5PRHPXxgOW
137
107
[ client-cli ] : https://github.com/WP-API/client-cli
138
108
[ api-console ] : https://github.com/WP-API/api-console
139
109
140
- <<<<<<< HEAD
141
110
142
- ベーシック認証
111
+ アプリケーションパスワードまたはベーシック認証
143
112
--------------------
144
113
ベーシック認証は、外部クライアントから利用できる認証の代替的な方法です。
145
114
OAuth 認証は複雑なので、開発段階ではベーシック認証が便利でしょう。
146
115
ただし、ベーシック認証ではすべてのリクエストにおいてユーザー名とパスワードを送る必要があり、
147
- 本番の環境で利用することは超非推奨です。
148
-
149
- ベーシック認証は、 [ HTTP Basic Authentication] [ http-basic ] (published as RFC2617) を利用しており [ Basic Auth plugin] [ basic-auth-plugin ] プラグインの有効化が必要です。
116
+ 本番の環境で利用することは断じて非推奨です。
150
117
151
- ベーシック認証の利用時、ユーザー名とパスワードは各リクエストの ` Authorization ` ヘッダーを通じて渡します。
152
- この値は、HTTP Basic 認証の仕様に従い、base64 でエンコードされるべきです。
118
+ アプリケーションパスワードも似たような用途で使用されます。しかしながらこれは、あなたの通常のWordPressパスワードに代わるもので、ユニークであり破棄することが簡単で、WordPressのプロフィール画面で変更することができるものです。これらのアプリケーションパスワードは、REST-APIや旧来のXML-RPCで使用されるもので、WordPressの管理画面にログインするために使用されるものではありません。
153
119
154
- 以下は、ベーシック認証による、WordPress のHTTP API を使った投稿の更新の例です。
155
- =======
156
- Application Passwords or Basic Authentication
157
- ---------------------------------------------
158
- Basic authentication is an optional authentication handler for external clients.
159
- Due to the complexity of OAuth authentication, basic authentication can be
160
- useful during development. However, Basic authentication requires passing your
161
- username and password on every request, as well as giving your credentials to
162
- clients, so it is heavily discouraged for production use.
120
+ ベーシック認証とアプリケーションパスワードは、[ HTTP Basic Authentication] [ http-basic ]
121
+ (published as RFC2617) を利用しており、[ Basic Auth plugin] [ basic-auth-plugin ] または
122
+ [ Application Passwords plugin] [ application-passwords ] のどちらかを有効化する必要があります。
163
123
164
- Application passwords are used similarly, however instead of providing your normal
165
- account password, unique and easily revokable passwords are generated from your
166
- edit profile screen in the WordPress admin. These application passwords are valid
167
- exclusively for the REST API and the legacy XML-RPC API and may not be used to log
168
- in to WordPress.
124
+ ベーシック認証を使用するには、ユーザー名とパスワードをリクエストごとに` Authentication ` ヘッダーで送信するだけです。この値は認証のたびにBase64エンドコードでエンコードされるべきです。
169
125
170
- Both basic authentication and application passwords use [ HTTP Basic Authentication] [ http-basic ]
171
- (published as RFC2617) and requires installing either the [ Basic Auth plugin] [ basic-auth-plugin ] or
172
- [ Application Passwords plugin] [ application-passwords ] respectively.
173
126
174
- To use Basic authentication, simply pass the username and password with each
175
- request through the ` Authorization ` header. This value should be encoded (using
176
- base64 encoding) as per the HTTP Basic specification.
127
+ これは、投稿をアップデートするためのサンプルで、WordPress HTTP APIを用いて認証を行っています。
177
128
178
- This is an example of how to update a post, using these authentications, via the
179
- WordPress HTTP API:
180
- >>>>>>> upstream/gh-pages
181
129
182
130
``` php
183
131
$headers = array (
@@ -186,7 +134,7 @@ $headers = array (
186
134
$url = rest_url( 'wp/v2/posts/1' );
187
135
188
136
$body = array(
189
- 'title' => 'Hello Gaia'
137
+ 'title' => 'Hello Gaia'
190
138
);
191
139
192
140
$response = wp_remote_post( $url, array (
@@ -195,8 +143,8 @@ $response = wp_remote_post( $url, array (
195
143
'body' => $data
196
144
) );
197
145
```
198
-
146
+
199
147
200
148
[ http-basic ] : https://tools.ietf.org/html/rfc2617
201
149
[ basic-auth-plugin ] : https://github.com/WP-API/Basic-Auth
202
- [ application-passwords ] : https://github.com/georgestephanis/application-passwords
150
+ [ application-passwords ] : https://github.com/georgestephanis/application-passwords
0 commit comments