Commit 0ed13e51 authored by Manas Verma's avatar Manas Verma Committed by Commit Bot

[Payments Autofill] Updating GetRealPan to include fido creation options in response.

Updating GetRealPan response to include FIDO Creation Options in order to initiate enrollment for the user into FIDO Authentication for card unmasking.

Bug: 949269
Change-Id: I9041ba2ebe27668b0c8db39ef9138056044a1703
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1719971Reviewed-by: default avatarJared Saul <jsaul@google.com>
Commit-Queue: Manas Verma <manasverma@google.com>
Cr-Commit-Position: refs/heads/master@{#686210}
parent 5bfdef58
...@@ -296,9 +296,13 @@ CreditCardAccessManager::GetOrCreateFIDOAuthenticator() { ...@@ -296,9 +296,13 @@ CreditCardAccessManager::GetOrCreateFIDOAuthenticator() {
void CreditCardAccessManager::OnCVCAuthenticationComplete( void CreditCardAccessManager::OnCVCAuthenticationComplete(
bool did_succeed, bool did_succeed,
const CreditCard* card, const CreditCard* card,
const base::string16& cvc) { const base::string16& cvc,
base::Value creation_options) {
is_authentication_in_progress_ = false; is_authentication_in_progress_ = false;
accessor_->OnCreditCardFetched(did_succeed, card, cvc); accessor_->OnCreditCardFetched(did_succeed, card, cvc);
// TODO(crbug/949269): Call CreditCardFIDOAuthenticator::Register() with given
// |creation_options|.
} }
#if !defined(OS_IOS) #if !defined(OS_IOS)
......
...@@ -137,7 +137,8 @@ class CreditCardAccessManager : public CreditCardCVCAuthenticator::Requester, ...@@ -137,7 +137,8 @@ class CreditCardAccessManager : public CreditCardCVCAuthenticator::Requester,
void OnCVCAuthenticationComplete( void OnCVCAuthenticationComplete(
bool did_succeed, bool did_succeed,
const CreditCard* card = nullptr, const CreditCard* card = nullptr,
const base::string16& cvc = base::string16()) override; const base::string16& cvc = base::string16(),
base::Value creation_options = base::Value()) override;
#if !defined(OS_IOS) #if !defined(OS_IOS)
// CreditCardFIDOAuthenticator::Requester: // CreditCardFIDOAuthenticator::Requester:
......
...@@ -33,10 +33,12 @@ void CreditCardCVCAuthenticator::Authenticate( ...@@ -33,10 +33,12 @@ void CreditCardCVCAuthenticator::Authenticate(
} }
void CreditCardCVCAuthenticator::OnFullCardRequestSucceeded( void CreditCardCVCAuthenticator::OnFullCardRequestSucceeded(
const payments::FullCardRequest& /*full_card_request*/, const payments::FullCardRequest& full_card_request,
const CreditCard& card, const CreditCard& card,
const base::string16& cvc) { const base::string16& cvc) {
requester_->OnCVCAuthenticationComplete(/*did_succeed=*/true, &card, cvc); requester_->OnCVCAuthenticationComplete(
/*did_succeed=*/true, &card, cvc,
full_card_request.GetFIDOCreationOptions());
} }
void CreditCardCVCAuthenticator::OnFullCardRequestFailed() { void CreditCardCVCAuthenticator::OnFullCardRequestFailed() {
......
...@@ -26,7 +26,8 @@ class CreditCardCVCAuthenticator ...@@ -26,7 +26,8 @@ class CreditCardCVCAuthenticator
virtual void OnCVCAuthenticationComplete( virtual void OnCVCAuthenticationComplete(
bool did_succeed, bool did_succeed,
const CreditCard* card = nullptr, const CreditCard* card = nullptr,
const base::string16& cvc = base::string16()) = 0; const base::string16& cvc = base::string16(),
base::Value creation_options = base::Value()) = 0;
}; };
explicit CreditCardCVCAuthenticator(AutofillClient* client); explicit CreditCardCVCAuthenticator(AutofillClient* client);
~CreditCardCVCAuthenticator() override; ~CreditCardCVCAuthenticator() override;
...@@ -39,7 +40,7 @@ class CreditCardCVCAuthenticator ...@@ -39,7 +40,7 @@ class CreditCardCVCAuthenticator
// payments::FullCardRequest::ResultDelegate // payments::FullCardRequest::ResultDelegate
void OnFullCardRequestSucceeded( void OnFullCardRequestSucceeded(
const payments::FullCardRequest& /*full_card_request*/, const payments::FullCardRequest& full_card_request,
const CreditCard& card, const CreditCard& card,
const base::string16& cvc) override; const base::string16& cvc) override;
void OnFullCardRequestFailed() override; void OnFullCardRequestFailed() override;
......
...@@ -199,6 +199,12 @@ void FullCardRequest::OnDidGetRealPan( ...@@ -199,6 +199,12 @@ void FullCardRequest::OnDidGetRealPan(
if (request_->user_response.should_store_pan) if (request_->user_response.should_store_pan)
personal_data_manager_->UpdateServerCreditCard(request_->card); personal_data_manager_->UpdateServerCreditCard(request_->card);
// TODO(crbug/949269): Once |fido_opt_in| is added to
// UserProvidedUnmaskDetails, add a check here that
// |user_response.fido_opt_in| is true before copying over
// |creation_options|.
if (response_details.fido_creation_options.is_dict())
fido_creation_options_ = response_details.fido_creation_options.Clone();
if (result_delegate_) if (result_delegate_)
result_delegate_->OnFullCardRequestSucceeded( result_delegate_->OnFullCardRequestSucceeded(
*this, request_->card, request_->user_response.cvc); *this, request_->card, request_->user_response.cvc);
...@@ -212,6 +218,10 @@ void FullCardRequest::OnDidGetRealPan( ...@@ -212,6 +218,10 @@ void FullCardRequest::OnDidGetRealPan(
} }
} }
base::Value FullCardRequest::GetFIDOCreationOptions() const {
return fido_creation_options_.Clone();
}
void FullCardRequest::Reset() { void FullCardRequest::Reset() {
weak_ptr_factory_.InvalidateWeakPtrs(); weak_ptr_factory_.InvalidateWeakPtrs();
payments_client_->CancelRequest(); payments_client_->CancelRequest();
...@@ -219,6 +229,7 @@ void FullCardRequest::Reset() { ...@@ -219,6 +229,7 @@ void FullCardRequest::Reset() {
ui_delegate_ = nullptr; ui_delegate_ = nullptr;
request_.reset(); request_.reset();
should_unmask_card_ = false; should_unmask_card_ = false;
fido_creation_options_ = base::Value();
} }
} // namespace payments } // namespace payments
......
...@@ -93,6 +93,9 @@ class FullCardRequest final : public CardUnmaskDelegate { ...@@ -93,6 +93,9 @@ class FullCardRequest final : public CardUnmaskDelegate {
AutofillClient::PaymentsRpcResult result, AutofillClient::PaymentsRpcResult result,
payments::PaymentsClient::UnmaskResponseDetails& response_details); payments::PaymentsClient::UnmaskResponseDetails& response_details);
// Returns a copy of |fido_creation_options_|.
base::Value GetFIDOCreationOptions() const;
base::TimeTicks form_parsed_timestamp() const { base::TimeTicks form_parsed_timestamp() const {
return form_parsed_timestamp_; return form_parsed_timestamp_;
} }
...@@ -158,6 +161,10 @@ class FullCardRequest final : public CardUnmaskDelegate { ...@@ -158,6 +161,10 @@ class FullCardRequest final : public CardUnmaskDelegate {
// The timestamp when the form is parsed. For histograms. // The timestamp when the form is parsed. For histograms.
base::TimeTicks form_parsed_timestamp_; base::TimeTicks form_parsed_timestamp_;
// Includes a challenge for enrolling user into FIDO Authentication for card
// unmasking.
base::Value fido_creation_options_;
// Enables destroying FullCardRequest while CVC prompt is showing or a server // Enables destroying FullCardRequest while CVC prompt is showing or a server
// communication is pending. // communication is pending.
base::WeakPtrFactory<FullCardRequest> weak_ptr_factory_{this}; base::WeakPtrFactory<FullCardRequest> weak_ptr_factory_{this};
......
...@@ -409,6 +409,11 @@ class UnmaskCardRequest : public PaymentsRequest { ...@@ -409,6 +409,11 @@ class UnmaskCardRequest : public PaymentsRequest {
void ParseResponse(const base::Value& response) override { void ParseResponse(const base::Value& response) override {
const auto* pan = response.FindStringKey("pan"); const auto* pan = response.FindStringKey("pan");
response_details_.real_pan = pan ? *pan : std::string(); response_details_.real_pan = pan ? *pan : std::string();
const auto* creation_options = response.FindKeyOfType(
"fido_creation_options", base::Value::Type::DICTIONARY);
if (creation_options)
response_details_.fido_creation_options = creation_options->Clone();
} }
bool IsResponseComplete() override { bool IsResponseComplete() override {
...@@ -947,7 +952,10 @@ PaymentsClient::UnmaskRequestDetails::~UnmaskRequestDetails() {} ...@@ -947,7 +952,10 @@ PaymentsClient::UnmaskRequestDetails::~UnmaskRequestDetails() {}
PaymentsClient::UnmaskResponseDetails::UnmaskResponseDetails() {} PaymentsClient::UnmaskResponseDetails::UnmaskResponseDetails() {}
PaymentsClient::UnmaskResponseDetails::UnmaskResponseDetails( PaymentsClient::UnmaskResponseDetails::UnmaskResponseDetails(
const UnmaskResponseDetails& other) = default; const UnmaskResponseDetails& other) {
real_pan = other.real_pan;
fido_creation_options = other.fido_creation_options.Clone();
}
PaymentsClient::UnmaskResponseDetails::~UnmaskResponseDetails() {} PaymentsClient::UnmaskResponseDetails::~UnmaskResponseDetails() {}
PaymentsClient::OptChangeRequestDetails::OptChangeRequestDetails() {} PaymentsClient::OptChangeRequestDetails::OptChangeRequestDetails() {}
......
...@@ -106,6 +106,7 @@ class PaymentsClient { ...@@ -106,6 +106,7 @@ class PaymentsClient {
} }
std::string real_pan; std::string real_pan;
base::Value fido_creation_options;
}; };
// Information required to either opt-in or opt-out a user for FIDO // Information required to either opt-in or opt-out a user for FIDO
...@@ -192,8 +193,8 @@ class PaymentsClient { ...@@ -192,8 +193,8 @@ class PaymentsClient {
void Prepare(); void Prepare();
// The user has interacted with a credit card form and may attempt to unmask a // The user has interacted with a credit card form and may attempt to unmask a
// card. This request returns what method of authentication is required, along // card. This request returns what method of authentication is suggested,
// with any information to facilitate the authentication. // along with any information to facilitate the authentication.
virtual void GetUnmaskDetails(GetUnmaskDetailsCallback callback, virtual void GetUnmaskDetails(GetUnmaskDetailsCallback callback,
const std::string& app_locale); const std::string& app_locale);
......
...@@ -425,6 +425,19 @@ TEST_F(PaymentsClientTest, UnmaskSuccessViaFIDO) { ...@@ -425,6 +425,19 @@ TEST_F(PaymentsClientTest, UnmaskSuccessViaFIDO) {
EXPECT_EQ("1234", unmask_response_details_->real_pan); EXPECT_EQ("1234", unmask_response_details_->real_pan);
} }
TEST_F(PaymentsClientTest, UnmaskSuccessViaCVCWithCreationOptions) {
StartUnmasking(CardUnmaskOptions().with_use_fido(false));
IssueOAuthToken();
ReturnResponse(net::HTTP_OK,
"{ \"pan\": \"1234\", \"fido_creation_options\": "
"{\"relying_party_id\": \"google.com\"}}");
EXPECT_EQ(AutofillClient::SUCCESS, result_);
EXPECT_EQ("1234", unmask_response_details_->real_pan);
EXPECT_EQ("google.com",
*unmask_response_details_->fido_creation_options.FindStringKey(
"relying_party_id"));
}
TEST_F(PaymentsClientTest, UnmaskSuccessAccountFromSyncTest) { TEST_F(PaymentsClientTest, UnmaskSuccessAccountFromSyncTest) {
EnableAutofillGetPaymentsIdentityFromSync(); EnableAutofillGetPaymentsIdentityFromSync();
StartUnmasking(CardUnmaskOptions()); StartUnmasking(CardUnmaskOptions());
......
...@@ -21,7 +21,8 @@ TestAuthenticationRequester::GetWeakPtr() { ...@@ -21,7 +21,8 @@ TestAuthenticationRequester::GetWeakPtr() {
void TestAuthenticationRequester::OnCVCAuthenticationComplete( void TestAuthenticationRequester::OnCVCAuthenticationComplete(
bool did_succeed, bool did_succeed,
const CreditCard* card, const CreditCard* card,
const base::string16& cvc) { const base::string16& cvc,
base::Value creation_options) {
did_succeed_ = did_succeed; did_succeed_ = did_succeed;
if (did_succeed_) { if (did_succeed_) {
DCHECK(card); DCHECK(card);
......
...@@ -39,7 +39,8 @@ class TestAuthenticationRequester ...@@ -39,7 +39,8 @@ class TestAuthenticationRequester
void OnCVCAuthenticationComplete( void OnCVCAuthenticationComplete(
bool did_succeed, bool did_succeed,
const CreditCard* card = nullptr, const CreditCard* card = nullptr,
const base::string16& cvc = base::string16()) override; const base::string16& cvc = base::string16(),
base::Value creation_options = base::Value()) override;
#if !defined(OS_IOS) #if !defined(OS_IOS)
// CreditCardFIDOAuthenticator::Requester: // CreditCardFIDOAuthenticator::Requester:
......
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