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
1916you are running in production mode, a bootstrap check prevents you from enabling
2017the 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
2320except 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
2623token, the amount of time (seconds) that the token expires in, the type, and the
2724scope 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
3027they are valid and after that time period, they can no longer be used. That time
3128period is defined by the `xpack.security.authc.token.timeout` setting. For more
3229information, 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
4138pertain 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/]
0 commit comments