Skip to content

Commit fb1c399

Browse files
authored
[DOCS] Splits the token APIs into separate pages (#32865)
1 parent 1efee66 commit fb1c399

File tree

6 files changed

+104
-63
lines changed

6 files changed

+104
-63
lines changed

docs/reference/redirects.asciidoc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,4 +511,12 @@ You can use the following APIs to add, remove, and retrieve roles in the native
511511

512512
* <<security-api-put-role,Create role>>, <<security-api-delete-role,Delete role>>
513513
* <<security-api-clear-role-cache,Clear roles cache>>
514-
* <<security-api-get-role,Get roles>>
514+
* <<security-api-get-role,Get roles>>
515+
516+
[role="exclude",id="security-api-tokens"]
517+
=== Token management APIs
518+
519+
You can use the following APIs to create and invalidate bearer tokens for access
520+
without requiring basic authentication:
521+
522+
* <<security-api-get-token,Get token>>, <<security-api-invalidate-token,Invalidate token>>

x-pack/docs/en/rest-api/security.asciidoc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ You can use the following APIs to perform {security} activities.
99
* <<security-api-privileges>>
1010
* <<security-api-role-mapping>>
1111
* <<security-api-ssl>>
12-
* <<security-api-tokens>>
1312
* <<security-api-users>>
1413

1514
[float]
@@ -22,15 +21,25 @@ You can use the following APIs to add, remove, and retrieve roles in the native
2221
* <<security-api-clear-role-cache,Clear roles cache>>
2322
* <<security-api-get-role,Get roles>>
2423

24+
[float]
25+
[[security-token-apis]]
26+
=== Tokens
27+
28+
You can use the following APIs to create and invalidate bearer tokens for access
29+
without requiring basic authentication:
30+
31+
* <<security-api-get-token,Get token>>, <<security-api-invalidate-token,Invalidate token>>
32+
2533
include::security/authenticate.asciidoc[]
2634
include::security/change-password.asciidoc[]
2735
include::security/clear-cache.asciidoc[]
2836
include::security/clear-roles-cache.asciidoc[]
2937
include::security/create-roles.asciidoc[]
3038
include::security/delete-roles.asciidoc[]
39+
include::security/delete-tokens.asciidoc[]
3140
include::security/get-roles.asciidoc[]
41+
include::security/get-tokens.asciidoc[]
3242
include::security/privileges.asciidoc[]
3343
include::security/role-mapping.asciidoc[]
3444
include::security/ssl.asciidoc[]
35-
include::security/tokens.asciidoc[]
3645
include::security/users.asciidoc[]
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
[role="xpack"]
2+
[[security-api-invalidate-token]]
3+
=== Delete token API
4+
5+
Invalidates a bearer token for access without requiring basic authentication.
6+
7+
==== Request
8+
9+
`DELETE /_xpack/security/oauth2/token`
10+
11+
==== Description
12+
13+
The tokens returned by the <<security-api-get-token,get token API>> have a
14+
finite period of time for which they are valid and after that time period, they
15+
can no longer be used. That time period is defined by the
16+
`xpack.security.authc.token.timeout` setting. For more information, see
17+
<<token-service-settings>>.
18+
19+
If you want to invalidate a token immediately, use this delete token API.
20+
21+
22+
==== Request Body
23+
24+
The following parameters can be specified in the body of a DELETE request and
25+
pertain to deleting a token:
26+
27+
`token` (required)::
28+
(string) An access token.
29+
30+
==== Examples
31+
32+
The following example invalidates the specified token immediately:
33+
34+
[source,js]
35+
--------------------------------------------------
36+
DELETE /_xpack/security/oauth2/token
37+
{
38+
"token" : "dGhpcyBpcyBub3QgYSByZWFsIHRva2VuIGJ1dCBpdCBpcyBvbmx5IHRlc3QgZGF0YS4gZG8gbm90IHRyeSB0byByZWFkIHRva2VuIQ=="
39+
}
40+
--------------------------------------------------
41+
// NOTCONSOLE
42+
43+
A successful call returns a JSON structure that indicates whether the token
44+
has already been invalidated.
45+
46+
[source,js]
47+
--------------------------------------------------
48+
{
49+
"created" : true <1>
50+
}
51+
--------------------------------------------------
52+
// NOTCONSOLE
53+
54+
<1> When a token has already been invalidated, `created` is set to false.
Lines changed: 28 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
[role="xpack"]
2-
[[security-api-tokens]]
3-
=== Token Management APIs
2+
[[security-api-get-token]]
3+
=== Get token API
44

5-
The `token` API enables you to create and invalidate bearer tokens for access
6-
without requiring basic authentication.
5+
Creates a bearer token for access without requiring basic authentication.
76

87
==== Request
98

10-
`POST /_xpack/security/oauth2/token` +
11-
12-
`DELETE /_xpack/security/oauth2/token`
9+
`POST /_xpack/security/oauth2/token`
1310

1411
==== Description
1512

@@ -19,20 +16,20 @@ you can explicitly enable the `xpack.security.authc.token.enabled` setting. When
1916
you are running in production mode, a bootstrap check prevents you from enabling
2017
the token service unless you also enable TLS on the HTTP interface.
2118

22-
The Get Token API takes the same parameters as a typical OAuth 2.0 token API
19+
The get token API takes the same parameters as a typical OAuth 2.0 token API
2320
except for the use of a JSON request body.
2421

25-
A successful Get Token API call returns a JSON structure that contains the access
22+
A successful get token API call returns a JSON structure that contains the access
2623
token, the amount of time (seconds) that the token expires in, the type, and the
2724
scope if available.
2825

29-
The tokens returned by the Get Token API have a finite period of time for which
26+
The tokens returned by the get token API have a finite period of time for which
3027
they are valid and after that time period, they can no longer be used. That time
3128
period is defined by the `xpack.security.authc.token.timeout` setting. For more
3229
information, see <<token-service-settings>>.
3330

34-
If you want to invalidate a token immediately, you can do so by using the Delete
35-
Token API.
31+
If you want to invalidate a token immediately, you can do so by using the
32+
<<security-api-invalidate-token,delete token API>>.
3633

3734

3835
==== Request Body
@@ -41,28 +38,28 @@ The following parameters can be specified in the body of a POST request and
4138
pertain to creating a token:
4239

4340
`grant_type`::
44-
(string) The type of grant. Currently only the `password` grant type is supported.
41+
(string) The type of grant. Valid grant types are: `password` and `refresh_token`.
4542

46-
`password` (required)::
47-
(string) The user's password.
43+
`password`::
44+
(string) The user's password. If you specify the `password` grant type, this
45+
parameter is required.
46+
47+
`refresh_token`::
48+
(string) If you specify the `refresh_token` grant type, this parameter is
49+
required. It contains the string that was returned when you created the token
50+
and enables you to extend its life.
4851

4952
`scope`::
5053
(string) The scope of the token. Currently tokens are only issued for a scope of
5154
`FULL` regardless of the value sent with the request.
5255

53-
`username` (required)::
54-
(string) The username that identifies the user.
55-
56-
The following parameters can be specified in the body of a DELETE request and
57-
pertain to deleting a token:
58-
59-
`token`::
60-
(string) An access token.
56+
`username`::
57+
(string) The username that identifies the user. If you specify the `password`
58+
grant type, this parameter is required.
6159

6260
==== Examples
63-
[[security-api-get-token]]
64-
To obtain a token, submit a POST request to the `/_xpack/security/oauth2/token`
65-
endpoint.
61+
62+
The following example obtains a token for the `test_admin` user:
6663

6764
[source,js]
6865
--------------------------------------------------
@@ -101,8 +98,8 @@ curl -H "Authorization: Bearer dGhpcyBpcyBub3QgYSByZWFsIHRva2VuIGJ1dCBpdCBpcyBvb
10198
// NOTCONSOLE
10299

103100
[[security-api-refresh-token]]
104-
To extend the life of an existing token, the token api may be called again with the refresh
105-
token within 24 hours of the token's creation.
101+
To extend the life of an existing token, you can call the API again with the
102+
refresh token within 24 hours of the token's creation. For example:
106103

107104
[source,js]
108105
--------------------------------------------------
@@ -116,7 +113,8 @@ POST /_xpack/security/oauth2/token
116113
// TEST[s/vLBPvmAB6KvwvJZr27cS/$body.refresh_token/]
117114
// TEST[continued]
118115

119-
The API will return a new token and refresh token. Each refresh token may only be used one time.
116+
The API will return a new token and refresh token. Each refresh token may only
117+
be used one time.
120118

121119
[source,js]
122120
--------------------------------------------------
@@ -128,32 +126,4 @@ The API will return a new token and refresh token. Each refresh token may only b
128126
}
129127
--------------------------------------------------
130128
// TESTRESPONSE[s/dGhpcyBpcyBub3QgYSByZWFsIHRva2VuIGJ1dCBpdCBpcyBvbmx5IHRlc3QgZGF0YS4gZG8gbm90IHRyeSB0byByZWFkIHRva2VuIQ==/$body.access_token/]
131-
// TESTRESPONSE[s/vLBPvmAB6KvwvJZr27cS/$body.refresh_token/]
132-
133-
[[security-api-invalidate-token]]
134-
If a token must be invalidated immediately, you can do so by submitting a DELETE
135-
request to `/_xpack/security/oauth2/token`. For example:
136-
137-
[source,js]
138-
--------------------------------------------------
139-
DELETE /_xpack/security/oauth2/token
140-
{
141-
"token" : "dGhpcyBpcyBub3QgYSByZWFsIHRva2VuIGJ1dCBpdCBpcyBvbmx5IHRlc3QgZGF0YS4gZG8gbm90IHRyeSB0byByZWFkIHRva2VuIQ=="
142-
}
143-
--------------------------------------------------
144-
// CONSOLE
145-
// TEST[s/dGhpcyBpcyBub3QgYSByZWFsIHRva2VuIGJ1dCBpdCBpcyBvbmx5IHRlc3QgZGF0YS4gZG8gbm90IHRyeSB0byByZWFkIHRva2VuIQ==/$body.access_token/]
146-
// TEST[continued]
147-
148-
A successful call returns a JSON structure that indicates whether the token
149-
has already been invalidated.
150-
151-
[source,js]
152-
--------------------------------------------------
153-
{
154-
"created" : true <1>
155-
}
156-
--------------------------------------------------
157-
// TESTRESPONSE
158-
159-
<1> When a token has already been invalidated, `created` is set to false.
129+
// TESTRESPONSE[s/vLBPvmAB6KvwvJZr27cS/$body.refresh_token/]

x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.security.get_token.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"xpack.security.get_token": {
3-
"documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-tokens.html#security-api-get-token",
3+
"documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-token.html",
44
"methods": [ "POST" ],
55
"url": {
66
"path": "/_xpack/security/oauth2/token",

x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.security.invalidate_token.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"xpack.security.invalidate_token": {
3-
"documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-tokens.html#security-api-invalidate-token",
3+
"documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-invalidate-token.html",
44
"methods": [ "DELETE" ],
55
"url": {
66
"path": "/_xpack/security/oauth2/token",

0 commit comments

Comments
 (0)