Skip to content

Commit bb19ffd

Browse files
committed
Moved commit "OAuth 2.0 token exchange. Allow multiple resource parameters. Update docs" from ydb repo
1 parent 5ee4cd3 commit bb19ffd

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

include/ydb-cpp-sdk/client/types/credentials/oauth2_token_exchange/credentials.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct TOauth2TokenExchangeParams {
4141

4242
FLUENT_SETTING_DEFAULT(std::string, GrantType, "urn:ietf:params:oauth:grant-type:token-exchange");
4343

44-
FLUENT_SETTING(std::string, Resource);
44+
FLUENT_SETTING_VECTOR_OR_SINGLE(std::string, Resource);
4545
FLUENT_SETTING_VECTOR_OR_SINGLE(std::string, Audience);
4646
FLUENT_SETTING_VECTOR_OR_SINGLE(std::string, Scope);
4747

include/ydb-cpp-sdk/client/types/credentials/oauth2_token_exchange/from_file.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ std::vector<std::string> GetSupportedOauth2TokenExchangeJwtAlgorithms();
1717
//
1818
// Fields of json file
1919
// grant-type: [string] Grant type option (default: see TOauth2TokenExchangeParams)
20-
// res: [string] Resource option (optional)
20+
// res: [string | list of strings] Resource option (optional)
2121
// aud: [string | list of strings] Audience option for token exchange request (optional)
2222
// scope: [string | list of strings] Scope option (optional)
2323
// requested-token-type: [string] Requested token type option (default: see TOauth2TokenExchangeParams)

src/client/types/credentials/oauth2_token_exchange/credentials.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,9 @@ class TOauth2TokenExchangeProviderImpl: public std::enable_shared_from_this<TOau
239239
}
240240
};
241241

242-
addIfNotEmpty("resource", Params.Resource_);
242+
for (const std::string& res : Params.Resource_) {
243+
params.emplace("resource", res);
244+
}
243245
for (const std::string& aud : Params.Audience_) {
244246
params.emplace("audience", aud);
245247
}

src/client/types/credentials/oauth2_token_exchange/from_file.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ TOauth2TokenExchangeParams ReadOauth2ConfigJson(const std::string& configJson, c
235235
}
236236

237237
PROCESS_JSON_STRING_PARAM("grant-type", GrantType, false);
238-
PROCESS_JSON_STRING_PARAM("res", Resource, false);
238+
PROCESS_JSON_ARRAY_PARAM("res", Resource);
239239
PROCESS_JSON_STRING_PARAM("requested-token-type", RequestedTokenType, false);
240240
PROCESS_JSON_ARRAY_PARAM("aud", Audience);
241241
PROCESS_JSON_ARRAY_PARAM("scope", Scope);

tests/unit/client/oauth2_token_exchange/credentials_ut.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,14 +930,16 @@ Y_UNIT_TEST_SUITE(TestTokenExchange) {
930930

931931
server.Check.ExpectedInputParams.erase("scope");
932932
server.Check.ExpectedInputParams.emplace("resource", "test_res");
933+
server.Check.ExpectedInputParams.emplace("resource", "test_res_2");
933934
server.Check.ExpectedInputParams.emplace("actor_token", "act_token");
934935
server.Check.ExpectedInputParams.emplace("actor_token_type", "act_token_type");
935936
server.Run(
936937
TOauth2TokenExchangeParams()
937938
.TokenEndpoint(server.GetEndpoint())
938939
.AppendAudience("test_aud")
939940
.AppendAudience("test_aud_2")
940-
.Resource("test_res")
941+
.AppendResource("test_res")
942+
.AppendResource("test_res_2")
941943
.SubjectTokenSource(CreateFixedTokenSource("test_token", "test_token_type"))
942944
.ActorTokenSource(CreateFixedTokenSource("act_token", "act_token_type")),
943945
"Bearer hello_token"
@@ -950,13 +952,19 @@ Y_UNIT_TEST_SUITE(TestTokenExchange) {
950952
server.Check.ExpectedInputParams.emplace("requested_token_type", "test_requested_token_type");
951953
server.Check.ExpectedInputParams.emplace("subject_token", "test_token");
952954
server.Check.ExpectedInputParams.emplace("subject_token_type", "test_token_type");
955+
server.Check.ExpectedInputParams.emplace("resource", "r1");
956+
server.Check.ExpectedInputParams.emplace("resource", "r2");
953957
server.Check.Response = R"({"access_token": "received_token", "token_type": "bEareR", "expires_in": 42})";
954958
server.RunFromConfig(
955959
TTestConfigFile()
956960
.Field("token-endpoint", "bla-bla-bla") // use explicit endpoint via param
957961
.Field("unknown", "unknown value")
958962
.Field("grant-type", "test_grant_type")
959963
.Field("requested-token-type", "test_requested_token_type")
964+
.Array("res")
965+
.Value("r1")
966+
.Value("r2")
967+
.Build()
960968
.SubMap("subject-credentials")
961969
.Field("type", "Fixed")
962970
.Field("token", "test_token")

0 commit comments

Comments
 (0)