Skip to content

Commit 02e056f

Browse files
Revert "Added parsing of Client Id from Access Token" (#619)
This reverts commit 7dc665f7c25bed7746d5933e40a5b961d2022044. * Due to new proper method of getting client id this change is removed. New public api call to get client id will be introduced Signed-off-by: Serhii Lozynskyi <[email protected]>
1 parent 2ce5310 commit 02e056f

File tree

6 files changed

+2
-107
lines changed

6 files changed

+2
-107
lines changed

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,6 @@ class AUTHENTICATION_API SignInResult {
7777
*/
7878
const std::string& GetAccessToken() const;
7979

80-
/**
81-
* @brief Gets client ID
82-
* @return The string that contains the client ID that is associated with the
83-
* access token. In case of parsing errors this method will return empty
84-
* string. Proper message will be printed to log.
85-
*/
86-
const std::string& GetClientId() const;
87-
8880
/**
8981
* @brief Gets the access token type.
9082
*

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ const std::string& SignInResult::GetAccessToken() const {
4444
return impl_->GetAccessToken();
4545
}
4646

47-
const std::string& SignInResult::GetClientId() const {
48-
return impl_->GetClientId();
49-
}
50-
5147
const std::string& SignInResult::GetTokenType() const {
5248
return impl_->GetTokenType();
5349
}

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

Lines changed: 1 addition & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,18 @@
1919

2020
#include "SignInResultImpl.h"
2121

22-
#include <vector>
23-
2422
#include "Constants.h"
2523
#include "olp/core/http/HttpStatusCode.h"
26-
#include "olp/core/logging/Log.h"
27-
#include "olp/core/utils/Base64.h"
2824

2925
namespace {
3026
constexpr auto kTokenType = "tokenType";
3127
constexpr auto kUserId = "userId";
3228
constexpr auto kScope = "scope";
33-
constexpr auto kLogTag = "SignIn";
34-
3529
} // namespace
3630

3731
namespace olp {
3832
namespace authentication {
3933

40-
namespace {
41-
bool IsJwtToken(const std::string& token) { return token.front() == 'e'; }
42-
43-
bool IsHnToken(const std::string& token) { return token.front() == 'h'; }
44-
} // namespace
45-
4634
SignInResultImpl::SignInResultImpl() noexcept
4735
: SignInResultImpl(http::HttpStatusCode::SERVICE_UNAVAILABLE,
4836
Constants::ERROR_HTTP_SERVICE_UNAVAILABLE) {}
@@ -62,10 +50,8 @@ SignInResultImpl::SignInResultImpl(
6250
status_ = http::HttpStatusCode::SERVICE_UNAVAILABLE;
6351
error_.message = Constants::ERROR_HTTP_SERVICE_UNAVAILABLE;
6452
} else {
65-
if (json_document->HasMember(Constants::ACCESS_TOKEN)) {
53+
if (json_document->HasMember(Constants::ACCESS_TOKEN))
6654
access_token_ = (*json_document)[Constants::ACCESS_TOKEN].GetString();
67-
client_id_ = ParseClientIdFromToken(access_token_.c_str());
68-
}
6955
if (json_document->HasMember(kTokenType))
7056
token_type_ = (*json_document)[kTokenType].GetString();
7157
if (json_document->HasMember(Constants::REFRESH_TOKEN))
@@ -90,8 +76,6 @@ const std::string& SignInResultImpl::GetAccessToken() const {
9076
return access_token_;
9177
}
9278

93-
const std::string& SignInResultImpl::GetClientId() const { return client_id_; }
94-
9579
const std::string& SignInResultImpl::GetTokenType() const {
9680
return token_type_;
9781
}
@@ -114,69 +98,5 @@ const std::string& SignInResultImpl::GetScope() const { return scope_; }
11498

11599
bool SignInResultImpl::IsValid() const { return is_valid_; }
116100

117-
std::string SignInResultImpl::ParseJwtToken(const std::string& token) {
118-
const std::string::size_type first_dot = token.find_first_of('.');
119-
if (first_dot == std::string::npos) {
120-
OLP_SDK_LOG_ERROR(kLogTag, "Cannot parse ClientId. Wrong token format.");
121-
return std::string();
122-
}
123-
124-
const std::string jws_header_encoded = token.substr(0, first_dot);
125-
126-
std::vector<std::uint8_t> decoded_bytes;
127-
if (!utils::Base64Decode(jws_header_encoded, decoded_bytes)) {
128-
OLP_SDK_LOG_ERROR(kLogTag,
129-
"Cannot parse ClientId. Non-decodable token format");
130-
return std::string();
131-
}
132-
133-
std::string jws_header_decoded;
134-
std::copy(decoded_bytes.begin(), decoded_bytes.end(),
135-
std::back_inserter(jws_header_decoded));
136-
137-
rapidjson::Document doc;
138-
doc.Parse(jws_header_decoded.c_str());
139-
140-
if (doc.HasParseError() || !doc.IsObject()) {
141-
OLP_SDK_LOG_ERROR(kLogTag, "Cannot parse ClientId. Defective token format");
142-
return std::string();
143-
}
144-
145-
auto client_id_field = doc.FindMember("aid");
146-
if (client_id_field == doc.MemberEnd() ||
147-
!client_id_field->value.IsString()) {
148-
OLP_SDK_LOG_ERROR(kLogTag,
149-
"Cannot parse ClientId. Field does not exist or is not "
150-
"a string json value");
151-
return std::string();
152-
}
153-
154-
const std::string result = client_id_field->value.GetString();
155-
156-
if (result.empty()) {
157-
OLP_SDK_LOG_ERROR(kLogTag,
158-
"Cannot parse ClientId. Incomplete token format");
159-
}
160-
161-
return result;
162-
}
163-
164-
std::string SignInResultImpl::ParseClientIdFromToken(const std::string& token) {
165-
if (token.empty()) {
166-
OLP_SDK_LOG_ERROR(kLogTag, "Token is empty");
167-
return std::string();
168-
}
169-
170-
if (IsJwtToken(token)) {
171-
return ParseJwtToken(token);
172-
} else if (IsHnToken(token)) {
173-
OLP_SDK_LOG_ERROR(kLogTag, "hN Tokens are not supported!");
174-
return std::string();
175-
} else {
176-
OLP_SDK_LOG_ERROR(kLogTag, "Unknown token format");
177-
return std::string();
178-
}
179-
}
180-
181101
} // namespace authentication
182102
} // namespace olp

olp-cpp-sdk-authentication/src/SignInResultImpl.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,6 @@ class SignInResultImpl : public BaseResult {
5151
*/
5252
const std::string& GetTokenType() const;
5353

54-
/**
55-
* @brief The client ID getter method
56-
* @return string containing the client id that is associated with the access
57-
* token
58-
*/
59-
const std::string& GetClientId() const;
60-
6154
/**
6255
* @brief Refresh token getter method
6356
* @return string containing a token which is used to obtain a new access
@@ -93,15 +86,11 @@ class SignInResultImpl : public BaseResult {
9386
const std::string& GetScope() const;
9487

9588
private:
96-
static std::string ParseJwtToken(const std::string&);
97-
static std::string ParseClientIdFromToken(const std::string& token);
98-
9989
bool is_valid_;
10090

10191
protected:
10292
std::string access_token_;
10393
std::string token_type_;
104-
std::string client_id_;
10594
time_t expiry_time_;
10695
std::chrono::seconds expires_in_;
10796

olp-cpp-sdk-authentication/tests/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
set(OLP_AUTHENTICATION_TEST_SOURCES
1919
AuthenticationCredentialsTest.cpp
20-
SignInResultImplTest.cpp
2120
)
2221

2322
if (ANDROID OR IOS)
@@ -71,4 +70,4 @@ else()
7170
PRIVATE
7271
${${PROJECT_NAME}_SOURCE_DIR}/src
7372
)
74-
endif()
73+
endif()

scripts/linux/fv/olp-common.variables

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export index_layer="olp-cpp-sdk-ingestion-test-index-layer"
1010
###
1111
export service_id="${appid}"
1212
export service_secret="${secret}"
13-
export service_client_id="${client_id}"
1413
export production_service_id="${production_service_id}"
1514
export production_service_secret="${production_service_secret}"
1615
export facebook_access_token="${facebook_access_token}"

0 commit comments

Comments
 (0)