Skip to content

Commit 2f3989e

Browse files
authored
Add device_id field to SignInProperties (#1329)
Add device_id property to the SignInProperties for implementing rate limiting by device functionality. Relates-To: OLPEDGE-2745 Signed-off-by: Yevhenii Dudnyk <[email protected]>
1 parent bee8a87 commit 2f3989e

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed

olp-cpp-sdk-authentication/include/olp/authentication/AuthenticationClient.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2020 HERE Europe B.V.
2+
* Copyright (C) 2019-2022 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -51,7 +51,8 @@ namespace authentication {
5151
class AuthenticationClientImpl;
5252

5353
/**
54-
* @brief Provides programmatic access to the HERE Account Authentication Service.
54+
* @brief Provides programmatic access to the HERE Account Authentication
55+
* Service.
5556
*
5657
* The supported APIs mirror the REST APIs currently available for the HERE
5758
* Account Authentication Service.
@@ -67,6 +68,14 @@ class AUTHENTICATION_API AuthenticationClient {
6768
*/
6869
boost::optional<std::string> scope{boost::none};
6970

71+
/**
72+
* @brief (Optional) The device ID assigned to the access token.
73+
*
74+
* @note This field is only necessary if you want to apply a oauth rate
75+
* limit on a particular device.
76+
*/
77+
boost::optional<std::string> device_id{boost::none};
78+
7079
/**
7180
* @brief (Optional) The number of seconds left before the access
7281
* token expires.

olp-cpp-sdk-authentication/src/AuthenticationClientImpl.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2021 HERE Europe B.V.
2+
* Copyright (C) 2020-2022 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -68,6 +68,7 @@ constexpr auto kEmail = "email";
6868
constexpr auto kFirstName = "firstname";
6969
constexpr auto kGrantType = "grantType";
7070
constexpr auto kScope = "scope";
71+
constexpr auto kDeviceId = "deviceId";
7172
constexpr auto kInviteToken = "inviteToken";
7273
constexpr auto kLanguage = "language";
7374
constexpr auto kLastName = "lastname";
@@ -792,6 +793,12 @@ client::OlpClient::RequestBodyType AuthenticationClientImpl::GenerateClientBody(
792793
writer.Key(kScope);
793794
writer.String(properties.scope.get().c_str());
794795
}
796+
797+
if (properties.device_id) {
798+
writer.Key(kDeviceId);
799+
writer.String(properties.device_id.get().c_str());
800+
}
801+
795802
writer.EndObject();
796803
auto content = data.GetString();
797804
return std::make_shared<RequestBodyData>(content, content + data.GetSize());

tests/integration/olp-cpp-sdk-authentication/AuthenticationClientTest.cpp

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2021 HERE Europe B.V.
2+
* Copyright (C) 2019-2022 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -2310,3 +2310,42 @@ TEST_F(AuthenticationClientTest, Timeout) {
23102310
testing::Mock::VerifyAndClearExpectations(network_.get());
23112311
}
23122312
}
2313+
2314+
TEST_F(AuthenticationClientTest, SignInWithDevice) {
2315+
auth::AuthenticationSettings settings;
2316+
settings.network_request_handler = network_;
2317+
settings.token_endpoint_url = kTokenEndpointUrl;
2318+
settings.task_scheduler =
2319+
client::OlpClientSettingsFactory::CreateDefaultTaskScheduler();
2320+
2321+
std::string body =
2322+
R"({"grantType":"client_credentials","deviceId":"my-device-1"})";
2323+
2324+
EXPECT_CALL(*network_,
2325+
Send(testing::AllOf(HeadersContainAuthorization(), BodyEq(body),
2326+
IsPostRequest(kRequestAuth)),
2327+
_, _, _, _))
2328+
.WillOnce(ReturnHttpResponse(
2329+
GetResponse(http::HttpStatusCode::OK).WithError(kErrorOk),
2330+
std::string()));
2331+
2332+
std::promise<void> request;
2333+
auth::AuthenticationClient::SignInClientResponse response;
2334+
auth::AuthenticationClient::SignInProperties properties;
2335+
properties.device_id = "my-device-1";
2336+
2337+
auto client =
2338+
std::make_unique<auth::AuthenticationClient>(std::move(settings));
2339+
2340+
client->SignInClient(
2341+
auth::AuthenticationCredentials(key_, secret_), properties,
2342+
[&](const auth::AuthenticationClient::SignInClientResponse& value) {
2343+
response = value;
2344+
request.set_value();
2345+
});
2346+
2347+
request.get_future().wait();
2348+
EXPECT_TRUE(response.IsSuccessful());
2349+
2350+
::testing::Mock::VerifyAndClearExpectations(network_.get());
2351+
}

0 commit comments

Comments
 (0)