Skip to content

Commit ef3c166

Browse files
committed
auth
1 parent 54ebcf4 commit ef3c166

File tree

2 files changed

+41
-21
lines changed

2 files changed

+41
-21
lines changed

source/includes/wp-api-v1/_authentication.md

+34-20
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Authentication #
22

3-
WooCommerce includes by default two ways to authenticate with the WP REST API, depending on whether the site supports SSL. It's still possible to use any [WP REST API authetication](http://v2.wp-api.org/guide/authentication/) plugin or method too.
3+
WooCommerce includes two ways to authenticate with the WP REST API. In addition, it is possible to use any [WP REST API authentication](http://v2.wp-api.org/guide/authentication/) plugin or method too.
44

55
### Over HTTPS ###
66

7-
You may use [HTTP Basic Auth](http://en.wikipedia.org/wiki/Basic_access_authentication) by providing the REST API Consumer Key as the username and the REST API Consumer Secret as the password.
7+
You may use [HTTP Basic Auth](http://en.wikipedia.org/wiki/Basic_access_authentication) by providing the REST API Consumer Key as the username and the REST API Consumer Secret as the password.
88

99
> HTTP Basic Auth example
1010
@@ -13,7 +13,7 @@ curl https://www.example.com/wc-api/v3/orders \
1313
-u consumer_key:consumer_secret
1414
```
1515

16-
Occasionally some servers may not parse the Authorization header correctly (if you see a "Consumer key is missing" error when authenticating over SSL, you have a server issue). In this case, you may provide the consumer key/secret as query string parameters.
16+
Occasionally some servers may not parse the Authorization header correctly (if you see a "Consumer key is missing" error when authenticating over SSL, you have a server issue). In this case, you may provide the consumer key/secret as query string parameters instead.
1717

1818
> Example for servers that not properly parse the Authorization header:
1919
@@ -23,46 +23,60 @@ curl https://www.example.com/wc-api/v3/orders?consumer_key=123&consumer_secret=a
2323

2424
### Over HTTP ###
2525

26-
You must use [OAuth 1.0a "one-legged" authentication](http://tools.ietf.org/html/rfc5849) to ensure REST API credentials cannot be intercepted. Typically you will use any standard OAuth 1.0a library in the language of choice to handle the authentication, or generate the necessary parameters by following the following instructions.
26+
You must use [OAuth 1.0a "one-legged" authentication](http://tools.ietf.org/html/rfc5849) to ensure REST API credentials cannot be intercepted by an attacker. Typically you will use any standard OAuth 1.0a library in the language of your choice to handle the authentication, or generate the necessary parameters by following the following instructions.
2727

2828
#### Generating an OAuth signature ####
2929

30-
1) Set the HTTP method for the request:
30+
1) Set the HTTP method for the request to `GET`
3131

32-
`GET`
32+
2) Set your base request URI -- this is the full request URI without query string parameters and URL encode according to RFC 3986.
3333

34-
2) Set your base request URI -- this is the full request URI without query string parameters -- and URL encode according to RFC 3986:
34+
> Example before encoding:
3535
36-
`http://www.example.com/wp-json/wc/v1/orders`
36+
```
37+
http://www.example.com/wp-json/wc/v1/orders
38+
```
39+
40+
> After encoding:
41+
42+
```
43+
http%3A%2F%2Fwww.example.com%2Fwp-json%2Fwc%2Fv1%2Forders
44+
```
3745

38-
when encoded:
46+
3) Collect and normalize your query string parameters. This includes all `oauth_*` parameters except for the signature itself. Parameters should be normalized using URL encoding according to RFC 3986 (use `rawurlencode` in PHP) and percent(`%`) characters should be double-encoded (e.g. `%` becomes `%25`.
3947

40-
`http%3A%2F%2Fwww.example.com%2Fwp-json%2Fwc%2Fv1%2Forders`
48+
4) Sort the parameters in byte-order.
4149

42-
3) Collect and normalize your query string parameters. This includes all `oauth_*` parameters except for the signature. Parameters should be normalized by URL encoding according to RFC 3986 (`rawurlencode` in PHP) and percent(`%`) characters should be double-encoded (e.g. `%` becomes `%25`.
50+
> PHP sorting example:
4351
44-
4) Sort the parameters in byte-order (`uksort( $params, 'strcmp' )` in PHP)
52+
```
53+
uksort( $params, 'strcmp' )
54+
```
4555

46-
5) Join each parameter with an encoded equals sign (`%3D`):
56+
5) Join each parameter with an encoded equals sign (`%3D`) and each key/value pair with an encoded ampersand (`%26`)
4757

48-
`oauth_signature_method%3DHMAC-SHA1`
58+
> Parameters example:
4959
50-
6) Join each parameter key/value with an encoded ampersand (`%26`):
60+
```
61+
oauth_consumer_key%3Dabc123%26oauth_signature_method%3DHMAC-SHA1
62+
```
5163

52-
`oauth_consumer_key%3Dabc123%26oauth_signature_method%3DHMAC-SHA1`
64+
6) Form the string to sign by joining the HTTP method, encoded base request URI, and encoded parameter string with an unencoded ampersand symbol (&)
5365

54-
7) Form the string to sign by joining the HTTP method, encoded base request URI, and encoded parameter string with an unencoded ampersand symbol (&):
66+
> Final string:
5567
56-
`GET&http%3A%2F%2Fwww.example.com%2Fwp-json%2Fwc%2Fv1%2Forders&oauth_consumer_key%3Dabc123%26oauth_signature_method%3DHMAC-SHA1`
68+
```
69+
GET&http%3A%2F%2Fwww.example.com%2Fwp-json%2Fwc%2Fv1%2Forders&oauth_consumer_key%3Dabc123%26oauth_signature_method%3DHMAC-SHA1
70+
```
5771

58-
8) Generate the signature using the string to key and your consumer secret key
72+
7) Generate the signature using the string to key and your consumer secret key
5973

6074
If you are having trouble generating a correct signature, you'll want to review the string you are signing for encoding errors. The [authentication source](https://github.com/woothemes/woocommerce/blob/master/includes/api/class-wc-rest-authentication.php#L141) can also be helpful in understanding how to properly generate the signature.
6175

6276
#### OAuth Tips ####
6377

6478
* The OAuth parameters must be added as query string parameters and *not* included in the Authorization header. This is because there is no reliable cross-platform way to get the raw request headers in WordPress.
65-
* The require parameters are: `oauth_consumer_key`, `oauth_timestamp`, `oauth_nonce`, `oauth_signature`, and `oauth_signature_method`. `oauth_version` is not required and should be omitted.
79+
* The required parameters are: `oauth_consumer_key`, `oauth_timestamp`, `oauth_nonce`, `oauth_signature`, and `oauth_signature_method`. `oauth_version` is not required and should be omitted.
6680
* HMAC-SHA1 or HMAC-SHA256 are the only accepted hash algorithms.
6781
* The OAuth nonce can be any randomly generated 32 character (recommended) string that is unique to the consumer key. Read more suggestions on [generating nonces on the Twitter REST API forums](https://dev.twitter.com/discussions/12445).
6882
* The OAuth timestamp should be the unix timestamp at the time of the request. The REST API will deny any requests that include a timestamp outside of a 15 minute window to prevent replay attacks.

source/stylesheets/screen.css.scss

+7-1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ html, body {
127127
color: $nav-active-text;
128128
a:hover {
129129
text-decoration: none;
130+
background-color: $nav-active-bg;
130131
}
131132
}
132133

@@ -329,6 +330,10 @@ html, body {
329330
margin-bottom: 20px;
330331
}
331332

333+
h4 {
334+
font-weight: bold;
335+
}
336+
332337
// h2s right after h1s should bump right up
333338
// against the h1s.
334339
h1 + h2, h1 + div + h2 {
@@ -486,7 +491,7 @@ html, body {
486491
clear:right;
487492
width: $examples-width;
488493
padding: 0 20px;
489-
white-space: pre-wrap;
494+
white-space: normal;
490495

491496
&>p { margin: 0; }
492497

@@ -500,6 +505,7 @@ html, body {
500505
pre {
501506
@extend %code-font;
502507
background: $examples-bg;
508+
white-space: pre-wrap;
503509

504510
code {
505511
padding: 20px;

0 commit comments

Comments
 (0)