Commit 8f0249ae authored by Mario Sanchez Prada's avatar Mario Sanchez Prada Committed by Commit Bot

Add |id_token| field to AccessTokenInfo

This hasn't yet been migrated from OAuth2AccessTokenConsumer::TokenResponse
and it will be useful at least to determine whether we are under advanced
protection from AdvancedProtectionStatusManager once a token is fetched.

Additional test coverage will be added in a follow-up patch.

TBR=thestig@chromium.org

Bug: 889764
Change-Id: Id9a8bcc7b2e3a5238b7a1c98f7787a8e905b6add
Reviewed-on: https://chromium-review.googlesource.com/1248625
Commit-Queue: Mario Sanchez Prada <mario@igalia.com>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594713}
parent 177ba2b6
...@@ -105,7 +105,8 @@ TEST_F(GCDApiFlowTest, SuccessOAuth2) { ...@@ -105,7 +105,8 @@ TEST_F(GCDApiFlowTest, SuccessOAuth2) {
gcd_flow_->OnAccessTokenFetchComplete( gcd_flow_->OnAccessTokenFetchComplete(
GoogleServiceAuthError::AuthErrorNone(), GoogleServiceAuthError::AuthErrorNone(),
identity::AccessTokenInfo( identity::AccessTokenInfo(
"SomeToken", base::Time::Now() + base::TimeDelta::FromHours(1))); "SomeToken", base::Time::Now() + base::TimeDelta::FromHours(1),
std::string() /* No extra information needed for this test */));
EXPECT_TRUE(base::ContainsKey(requested_urls, GURL(kConfirmRequest))); EXPECT_TRUE(base::ContainsKey(requested_urls, GURL(kConfirmRequest)));
...@@ -134,7 +135,8 @@ TEST_F(GCDApiFlowTest, BadJson) { ...@@ -134,7 +135,8 @@ TEST_F(GCDApiFlowTest, BadJson) {
gcd_flow_->OnAccessTokenFetchComplete( gcd_flow_->OnAccessTokenFetchComplete(
GoogleServiceAuthError::AuthErrorNone(), GoogleServiceAuthError::AuthErrorNone(),
identity::AccessTokenInfo( identity::AccessTokenInfo(
"SomeToken", base::Time::Now() + base::TimeDelta::FromHours(1))); "SomeToken", base::Time::Now() + base::TimeDelta::FromHours(1),
std::string() /* No extra information needed for this test */));
EXPECT_TRUE(base::ContainsKey(requested_urls, GURL(kConfirmRequest))); EXPECT_TRUE(base::ContainsKey(requested_urls, GURL(kConfirmRequest)));
test_url_loader_factory_.AddResponse(kConfirmRequest, test_url_loader_factory_.AddResponse(kConfirmRequest,
......
...@@ -81,9 +81,10 @@ void AccessTokenFetcher::OnGetTokenSuccess( ...@@ -81,9 +81,10 @@ void AccessTokenFetcher::OnGetTokenSuccess(
std::unique_ptr<OAuth2TokenService::Request> request_deleter( std::unique_ptr<OAuth2TokenService::Request> request_deleter(
std::move(access_token_request_)); std::move(access_token_request_));
RunCallbackAndMaybeDie(GoogleServiceAuthError::AuthErrorNone(), RunCallbackAndMaybeDie(
GoogleServiceAuthError::AuthErrorNone(),
AccessTokenInfo(token_response.access_token, AccessTokenInfo(token_response.access_token,
token_response.expiration_time)); token_response.expiration_time, token_response.id_token));
// Potentially dead after the above invocation; nothing to do except return. // Potentially dead after the above invocation; nothing to do except return.
} }
......
...@@ -44,8 +44,11 @@ class AccessTokenFetcherTest : public testing::Test, ...@@ -44,8 +44,11 @@ class AccessTokenFetcherTest : public testing::Test,
AccessTokenFetcherTest() AccessTokenFetcherTest()
: signin_client_(&pref_service_), : signin_client_(&pref_service_),
token_service_(&pref_service_), token_service_(&pref_service_),
access_token_info_("access token", access_token_info_(
base::Time::Now() + base::TimeDelta::FromHours(1)) { "access token",
base::Time::Now() + base::TimeDelta::FromHours(1),
std::
string() /* TODO(https://crbug.com/889764): Check id_token is passed along */) {
AccountTrackerService::RegisterPrefs(pref_service_.registry()); AccountTrackerService::RegisterPrefs(pref_service_.registry());
account_tracker_ = std::make_unique<AccountTrackerService>(); account_tracker_ = std::make_unique<AccountTrackerService>();
......
...@@ -8,7 +8,8 @@ namespace identity { ...@@ -8,7 +8,8 @@ namespace identity {
bool operator==(const AccessTokenInfo& lhs, const AccessTokenInfo& rhs) { bool operator==(const AccessTokenInfo& lhs, const AccessTokenInfo& rhs) {
return (lhs.token == rhs.token) && return (lhs.token == rhs.token) &&
(lhs.expiration_time == rhs.expiration_time); (lhs.expiration_time == rhs.expiration_time) &&
(lhs.id_token == rhs.id_token);
} }
} // namespace identity } // namespace identity
...@@ -20,10 +20,18 @@ struct AccessTokenInfo { ...@@ -20,10 +20,18 @@ struct AccessTokenInfo {
// The time at which this access token will expire. // The time at which this access token will expire.
base::Time expiration_time; base::Time expiration_time;
// Contains extra information regarding the user's currently registered
// services. It is uncommon for consumers to need to interact with this field.
// To interact with it, first parse it via gaia::ParseServiceFlags().
std::string id_token;
AccessTokenInfo() = default; AccessTokenInfo() = default;
AccessTokenInfo(const std::string& token_param, AccessTokenInfo(const std::string& token_param,
const base::Time& expiration_time_param) const base::Time& expiration_time_param,
: token(token_param), expiration_time(expiration_time_param) {} const std::string& id_token)
: token(token_param),
expiration_time(expiration_time_param),
id_token(id_token) {}
}; };
// Defined for testing purposes only. // Defined for testing purposes only.
......
...@@ -48,8 +48,12 @@ class PrimaryAccountAccessTokenFetcherTest : public testing::Test, ...@@ -48,8 +48,12 @@ class PrimaryAccountAccessTokenFetcherTest : public testing::Test,
StrictMock<MockCallback<AccessTokenFetcher::TokenCallback>>; StrictMock<MockCallback<AccessTokenFetcher::TokenCallback>>;
PrimaryAccountAccessTokenFetcherTest() PrimaryAccountAccessTokenFetcherTest()
: access_token_info_("access token", : access_token_info_(
base::Time::Now() + base::TimeDelta::FromHours(1)) {} "access token",
base::Time::Now() + base::TimeDelta::FromHours(1),
std::
string() /* TODO(https://crbug.com/889764): Check id_token is passed along */) {
}
~PrimaryAccountAccessTokenFetcherTest() override { ~PrimaryAccountAccessTokenFetcherTest() override {
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment