1
1
[role="xpack"]
2
- [[security-api-tokens ]]
3
- === Token Management APIs
2
+ [[security-api-get-token ]]
3
+ === Get token API
4
4
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.
7
6
8
7
==== Request
9
8
10
- `POST /_xpack/security/oauth2/token` +
11
-
12
- `DELETE /_xpack/security/oauth2/token`
9
+ `POST /_xpack/security/oauth2/token`
13
10
14
11
==== Description
15
12
@@ -19,20 +16,20 @@ you can explicitly enable the `xpack.security.authc.token.enabled` setting. When
19
16
you are running in production mode, a bootstrap check prevents you from enabling
20
17
the token service unless you also enable TLS on the HTTP interface.
21
18
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
23
20
except for the use of a JSON request body.
24
21
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
26
23
token, the amount of time (seconds) that the token expires in, the type, and the
27
24
scope if available.
28
25
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
30
27
they are valid and after that time period, they can no longer be used. That time
31
28
period is defined by the `xpack.security.authc.token.timeout` setting. For more
32
29
information, see <<token-service-settings>>.
33
30
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>> .
36
33
37
34
38
35
==== Request Body
@@ -41,28 +38,28 @@ The following parameters can be specified in the body of a POST request and
41
38
pertain to creating a token:
42
39
43
40
`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` .
45
42
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.
48
51
49
52
`scope`::
50
53
(string) The scope of the token. Currently tokens are only issued for a scope of
51
54
`FULL` regardless of the value sent with the request.
52
55
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.
61
59
62
60
==== 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:
66
63
67
64
[source,js]
68
65
--------------------------------------------------
@@ -101,8 +98,8 @@ curl -H "Authorization: Bearer dGhpcyBpcyBub3QgYSByZWFsIHRva2VuIGJ1dCBpdCBpcyBvb
101
98
// NOTCONSOLE
102
99
103
100
[[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:
106
103
107
104
[source,js]
108
105
--------------------------------------------------
@@ -116,7 +113,8 @@ POST /_xpack/security/oauth2/token
116
113
// TEST[s/vLBPvmAB6KvwvJZr27cS/$body.refresh_token/]
117
114
// TEST[continued]
118
115
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.
120
118
121
119
[source,js]
122
120
--------------------------------------------------
@@ -128,32 +126,4 @@ The API will return a new token and refresh token. Each refresh token may only b
128
126
}
129
127
--------------------------------------------------
130
128
// 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