2
2
title : 認証
3
3
---
4
4
5
+ <<<<<<< HEAD
5
6
このAPIにおいては、認証には2つの選択肢があり、基本的に以下のように選びましょう。
6
7
7
8
* そのサイトで有効化されたテーマやプラグインから利用するのであれば ** クッキー認証**
8
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
9
18
10
19
クッキー認証
11
20
---------------------
@@ -21,6 +30,7 @@ title: 認証
21
30
独自のデータモデルからアクセスする場合には、 ` wp.api.models.Base ` を継承することで、
22
31
あらゆるカスタムリクエストで nonce がきちんと送信されることが保証されます。
23
32
33
+ <<<<<<< HEAD
24
34
マニュアルで Ajax リクエストを送る場合、nonce は各リクエストで毎回送信する必要があります。
25
35
送信された nonce は ` wp_rest ` にセットされたアクションと一緒に利用されます。
26
36
API への nonce の受け渡しは、POST のデータや GET のクエリの ` _wpnonce ` パラメータ、
@@ -32,6 +42,21 @@ Note: Until recently, most software had spotty support for `DELETE` requests. Fo
32
42
このクッキー認証が利用できるのは、REST API が WordPress の内部から使われていて、
33
43
かつ、ユーザーがログインしている時のみであるということです。
34
44
さらに、そのログインユーザーが、実行しようとしているアクションに必要な権限を与えられているということも条件となります。
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
35
60
36
61
以下は、ビルトインの Javascript クライアントが nonce を生成する例です。
37
62
@@ -80,9 +105,14 @@ OAuth 認証でも、ユーザーは通常の WordPress ログイン画面を通
80
105
その後、自身に代わって処理を行うクライアントを認証します。
81
106
クライアントには、OAuth トークンが発行され、API へのアクセスが許可されます。このアクセス権はユーザー側からいつでも取り消すことができます。
82
107
108
+ <<<<<<< HEAD
83
109
OAuth 認証は、[ OAuth 1.0a specification] [ oauth ] (published as
84
110
RFC5849) を利用しており、[ OAuth plugin] [ oauth-plugin ] がサイトで
85
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
86
116
87
117
WP API と OAuth サーバー用のプラグインを有効化したら、コンシューマを作成しましょう。
88
118
コンシューマは、アプリケーションの識別子であり、サイトとリンクするために必要な key と secret からなります。
@@ -107,6 +137,7 @@ Secret: LnUdIsyhPFnURkatekRIAUfYV7nmP4iF3AVxkS5PRHPXxgOW
107
137
[ client-cli ] : https://github.com/WP-API/client-cli
108
138
[ api-console ] : https://github.com/WP-API/api-console
109
139
140
+ <<<<<<< HEAD
110
141
111
142
ベーシック認証
112
143
--------------------
@@ -121,6 +152,32 @@ OAuth 認証は複雑なので、開発段階ではベーシック認証が便
121
152
この値は、HTTP Basic 認証の仕様に従い、base64 でエンコードされるべきです。
122
153
123
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.
163
+
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.
169
+
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
+
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.
177
+
178
+ This is an example of how to update a post, using these authentications, via the
179
+ WordPress HTTP API:
180
+ >>>>>>> upstream/gh-pages
124
181
125
182
``` php
126
183
$headers = array (
@@ -142,3 +199,4 @@ $response = wp_remote_post( $url, array (
142
199
143
200
[ http-basic ] : https://tools.ietf.org/html/rfc2617
144
201
[ basic-auth-plugin ] : https://github.com/WP-API/Basic-Auth
202
+ [ application-passwords ] : https://github.com/georgestephanis/application-passwords
0 commit comments