-
Notifications
You must be signed in to change notification settings - Fork 25.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Token API supports the client_credentials grant #33106
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6b0ce08
Token API supports the client_credentials grant
jaymode 436a737
Merge branch 'master' into token_client_creds
jaymode 70e957d
address doc comment
jaymode 13fbb62
remove v5 constant use
jaymode 209b94c
Merge branch 'master' into token_client_creds
jaymode 7b4be47
reorder docs to fix test failure
jaymode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...est/java/org/elasticsearch/xpack/core/security/action/token/CreateTokenResponseTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.core.security.action.token; | ||
|
||
import org.elasticsearch.Version; | ||
import org.elasticsearch.common.io.stream.BytesStreamOutput; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.unit.TimeValue; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.elasticsearch.test.VersionUtils; | ||
|
||
public class CreateTokenResponseTests extends ESTestCase { | ||
|
||
public void testSerialization() throws Exception { | ||
CreateTokenResponse response = new CreateTokenResponse(randomAlphaOfLengthBetween(1, 10), TimeValue.timeValueMinutes(20L), | ||
randomBoolean() ? null : "FULL", randomAlphaOfLengthBetween(1, 10)); | ||
try (BytesStreamOutput output = new BytesStreamOutput()) { | ||
response.writeTo(output); | ||
try (StreamInput input = output.bytes().streamInput()) { | ||
CreateTokenResponse serialized = new CreateTokenResponse(); | ||
serialized.readFrom(input); | ||
assertEquals(response, serialized); | ||
} | ||
} | ||
|
||
response = new CreateTokenResponse(randomAlphaOfLengthBetween(1, 10), TimeValue.timeValueMinutes(20L), | ||
randomBoolean() ? null : "FULL", null); | ||
try (BytesStreamOutput output = new BytesStreamOutput()) { | ||
response.writeTo(output); | ||
try (StreamInput input = output.bytes().streamInput()) { | ||
CreateTokenResponse serialized = new CreateTokenResponse(); | ||
serialized.readFrom(input); | ||
assertEquals(response, serialized); | ||
} | ||
} | ||
} | ||
|
||
public void testSerializationToPre62Version() throws Exception { | ||
CreateTokenResponse response = new CreateTokenResponse(randomAlphaOfLengthBetween(1, 10), TimeValue.timeValueMinutes(20L), | ||
randomBoolean() ? null : "FULL", randomBoolean() ? null : randomAlphaOfLengthBetween(1, 10)); | ||
final Version version = VersionUtils.randomVersionBetween(random(), Version.V_5_6_0, Version.V_6_1_4); | ||
try (BytesStreamOutput output = new BytesStreamOutput()) { | ||
output.setVersion(version); | ||
response.writeTo(output); | ||
try (StreamInput input = output.bytes().streamInput()) { | ||
input.setVersion(version); | ||
CreateTokenResponse serialized = new CreateTokenResponse(); | ||
serialized.readFrom(input); | ||
assertNull(serialized.getRefreshToken()); | ||
assertEquals(response.getTokenString(), serialized.getTokenString()); | ||
assertEquals(response.getExpiresIn(), serialized.getExpiresIn()); | ||
assertEquals(response.getScope(), serialized.getScope()); | ||
} | ||
} | ||
} | ||
|
||
public void testSerializationToPost62Pre65Version() throws Exception { | ||
CreateTokenResponse response = new CreateTokenResponse(randomAlphaOfLengthBetween(1, 10), TimeValue.timeValueMinutes(20L), | ||
randomBoolean() ? null : "FULL", randomAlphaOfLengthBetween(1, 10)); | ||
final Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_2_0, Version.V_6_4_0); | ||
try (BytesStreamOutput output = new BytesStreamOutput()) { | ||
output.setVersion(version); | ||
response.writeTo(output); | ||
try (StreamInput input = output.bytes().streamInput()) { | ||
input.setVersion(version); | ||
CreateTokenResponse serialized = new CreateTokenResponse(); | ||
serialized.readFrom(input); | ||
assertEquals(response, serialized); | ||
} | ||
} | ||
|
||
// no refresh token | ||
response = new CreateTokenResponse(randomAlphaOfLengthBetween(1, 10), TimeValue.timeValueMinutes(20L), | ||
randomBoolean() ? null : "FULL", null); | ||
try (BytesStreamOutput output = new BytesStreamOutput()) { | ||
output.setVersion(version); | ||
response.writeTo(output); | ||
try (StreamInput input = output.bytes().streamInput()) { | ||
input.setVersion(version); | ||
CreateTokenResponse serialized = new CreateTokenResponse(); | ||
serialized.readFrom(input); | ||
assertEquals("", serialized.getRefreshToken()); | ||
assertEquals(response.getTokenString(), serialized.getTokenString()); | ||
assertEquals(response.getExpiresIn(), serialized.getExpiresIn()); | ||
assertEquals(response.getScope(), serialized.getScope()); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think flowing from the
client_credentials
example straight into a discussion onrefresh_token
is confusing because client_credentials doesn't provide a refresh token, and it will undoubtedly trip up some readers.Maybe the refresh token section can indicate that only "password" grants provide refresh tokens?