Commit 9b64a1d4 authored by Manas Verma's avatar Manas Verma Committed by Commit Bot

[Autofill Auth] Changing OnCVCAuthenticationComplete() to take in struct.

Changing CreditCardAccessManager::OnCVCAuthenticationComplete() to take in a
struct. Eventually will need to include an authorization token as part of the
response, so changing this to a struct will keep things clean.

Bug: 949269
Change-Id: I682c6abfe474427c36b035e3416168f08aed2c58
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1761368Reviewed-by: default avatarJared Saul <jsaul@google.com>
Reviewed-by: default avatarTommy Martino <tmartino@chromium.org>
Commit-Queue: Manas Verma <manasverma@google.com>
Cr-Commit-Position: refs/heads/master@{#692964}
parent de4d8e57
...@@ -294,23 +294,25 @@ CreditCardAccessManager::GetOrCreateFIDOAuthenticator() { ...@@ -294,23 +294,25 @@ CreditCardAccessManager::GetOrCreateFIDOAuthenticator() {
#endif #endif
void CreditCardAccessManager::OnCVCAuthenticationComplete( void CreditCardAccessManager::OnCVCAuthenticationComplete(
bool did_succeed, const CreditCardCVCAuthenticator::CVCAuthenticationResponse& response) {
const CreditCard* card,
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(response.did_succeed, response.card,
response.cvc);
if (!did_succeed) if (!response.did_succeed)
return; return;
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
// Now that unmask flow is complete, on Android, if GetRealPan includes // Now that unmask flow is complete, on Android, if GetRealPan includes
// |creation_options|, completely hand over registration flow to // |creation_options|, completely hand over registration flow to
// CreditCardFIDOAuthenticator. // CreditCardFIDOAuthenticator.
if (creation_options.is_dict()) if (response.creation_options.has_value()) {
GetOrCreateFIDOAuthenticator()->Register(std::move(creation_options)); DCHECK(response.creation_options->is_dict());
#elif !defined(OS_IOS) // CreditCardFIDOAuthenticator does not exist on iOS. GetOrCreateFIDOAuthenticator()->Register(
response.creation_options->Clone());
}
#elif !defined(OS_IOS)
// CreditCardFIDOAuthenticator does not exist on iOS.
// On desktop, prompts dialog to show the authentication offer. // On desktop, prompts dialog to show the authentication offer.
if (unmask_details_.offer_fido_opt_in) if (unmask_details_.offer_fido_opt_in)
GetOrCreateFIDOAuthenticator()->ShowWebauthnOfferDialog(); GetOrCreateFIDOAuthenticator()->ShowWebauthnOfferDialog();
......
...@@ -135,10 +135,8 @@ class CreditCardAccessManager : public CreditCardCVCAuthenticator::Requester, ...@@ -135,10 +135,8 @@ class CreditCardAccessManager : public CreditCardCVCAuthenticator::Requester,
// CreditCardCVCAuthenticator::Requester: // CreditCardCVCAuthenticator::Requester:
void OnCVCAuthenticationComplete( void OnCVCAuthenticationComplete(
bool did_succeed, const CreditCardCVCAuthenticator::CVCAuthenticationResponse& response)
const CreditCard* card = nullptr, 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:
......
...@@ -230,10 +230,10 @@ class CreditCardAccessManagerTest : public testing::Test { ...@@ -230,10 +230,10 @@ class CreditCardAccessManagerTest : public testing::Test {
if (fido_opt_in) { if (fido_opt_in) {
response.fido_creation_options = response.fido_creation_options =
base::Value(base::Value::Type::DICTIONARY); base::Value(base::Value::Type::DICTIONARY);
response.fido_creation_options.SetKey("relying_party_id", response.fido_creation_options->SetKey("relying_party_id",
base::Value(kGooglePaymentsRpid)); base::Value(kGooglePaymentsRpid));
response.fido_creation_options.SetKey("challenge", response.fido_creation_options->SetKey("challenge",
base::Value(kTestChallenge)); base::Value(kTestChallenge));
} }
#endif #endif
full_card_request->OnDidGetRealPan(result, full_card_request->OnDidGetRealPan(result,
......
...@@ -11,6 +11,11 @@ ...@@ -11,6 +11,11 @@
namespace autofill { namespace autofill {
CreditCardCVCAuthenticator::CVCAuthenticationResponse::
CVCAuthenticationResponse() {}
CreditCardCVCAuthenticator::CVCAuthenticationResponse::
~CVCAuthenticationResponse() {}
CreditCardCVCAuthenticator::CreditCardCVCAuthenticator(AutofillClient* client) CreditCardCVCAuthenticator::CreditCardCVCAuthenticator(AutofillClient* client)
: client_(client) {} : client_(client) {}
...@@ -37,12 +42,18 @@ void CreditCardCVCAuthenticator::OnFullCardRequestSucceeded( ...@@ -37,12 +42,18 @@ void CreditCardCVCAuthenticator::OnFullCardRequestSucceeded(
const CreditCard& card, const CreditCard& card,
const base::string16& cvc) { const base::string16& cvc) {
requester_->OnCVCAuthenticationComplete( requester_->OnCVCAuthenticationComplete(
/*did_succeed=*/true, &card, cvc, CVCAuthenticationResponse()
full_card_request.GetFIDOCreationOptions()); .with_did_succeed(true)
.with_card(&card)
.with_cvc(cvc)
.with_creation_options(
std::move(full_card_request.unmask_response_details()
.fido_creation_options)));
} }
void CreditCardCVCAuthenticator::OnFullCardRequestFailed() { void CreditCardCVCAuthenticator::OnFullCardRequestFailed() {
requester_->OnCVCAuthenticationComplete(/*did_succeed=*/false); requester_->OnCVCAuthenticationComplete(
CVCAuthenticationResponse().with_did_succeed(false));
} }
void CreditCardCVCAuthenticator::ShowUnmaskPrompt( void CreditCardCVCAuthenticator::ShowUnmaskPrompt(
......
...@@ -20,14 +20,38 @@ class CreditCardCVCAuthenticator ...@@ -20,14 +20,38 @@ class CreditCardCVCAuthenticator
: public payments::FullCardRequest::ResultDelegate, : public payments::FullCardRequest::ResultDelegate,
public payments::FullCardRequest::UIDelegate { public payments::FullCardRequest::UIDelegate {
public: public:
struct CVCAuthenticationResponse {
CVCAuthenticationResponse();
~CVCAuthenticationResponse();
CVCAuthenticationResponse& with_did_succeed(bool b) {
did_succeed = b;
return *this;
}
// Data pointed to by |c| must outlive this object.
CVCAuthenticationResponse& with_card(const CreditCard* c) {
card = c;
return *this;
}
CVCAuthenticationResponse& with_cvc(const base::string16 s) {
cvc = base::string16(s);
return *this;
}
CVCAuthenticationResponse& with_creation_options(
base::Optional<base::Value> v) {
creation_options = std::move(v);
return *this;
}
bool did_succeed = false;
const CreditCard* card = nullptr;
base::string16 cvc = base::string16();
base::Optional<base::Value> creation_options = base::nullopt;
};
class Requester { class Requester {
public: public:
virtual ~Requester() {} virtual ~Requester() {}
virtual void OnCVCAuthenticationComplete( virtual void OnCVCAuthenticationComplete(
bool did_succeed, const CVCAuthenticationResponse& response) = 0;
const CreditCard* card = nullptr,
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;
......
...@@ -200,11 +200,10 @@ void FullCardRequest::OnDidGetRealPan( ...@@ -200,11 +200,10 @@ void FullCardRequest::OnDidGetRealPan(
personal_data_manager_->UpdateServerCreditCard(request_->card); personal_data_manager_->UpdateServerCreditCard(request_->card);
// TODO(crbug/949269): Once |fido_opt_in| is added to // TODO(crbug/949269): Once |fido_opt_in| is added to
// UserProvidedUnmaskDetails, add a check here that // UserProvidedUnmaskDetails, clear out |creation_options| from
// |user_response.fido_opt_in| is true before copying over // |response_details_| if |user_response.fido_opt_in| was not set to true
// |creation_options|. // to avoid an unwanted registration prompt.
if (response_details.fido_creation_options.is_dict()) unmask_response_details_ = response_details;
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);
...@@ -218,10 +217,6 @@ void FullCardRequest::OnDidGetRealPan( ...@@ -218,10 +217,6 @@ 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();
...@@ -229,7 +224,7 @@ void FullCardRequest::Reset() { ...@@ -229,7 +224,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(); unmask_response_details_ = payments::PaymentsClient::UnmaskResponseDetails();
} }
} // namespace payments } // namespace payments
......
...@@ -93,8 +93,10 @@ class FullCardRequest final : public CardUnmaskDelegate { ...@@ -93,8 +93,10 @@ 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_|. payments::PaymentsClient::UnmaskResponseDetails unmask_response_details()
base::Value GetFIDOCreationOptions() const; const {
return unmask_response_details_;
}
base::TimeTicks form_parsed_timestamp() const { base::TimeTicks form_parsed_timestamp() const {
return form_parsed_timestamp_; return form_parsed_timestamp_;
...@@ -161,9 +163,8 @@ class FullCardRequest final : public CardUnmaskDelegate { ...@@ -161,9 +163,8 @@ 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 // Includes all details from GetRealPan response.
// unmasking. payments::PaymentsClient::UnmaskResponseDetails unmask_response_details_;
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.
......
...@@ -957,10 +957,19 @@ PaymentsClient::UnmaskRequestDetails::~UnmaskRequestDetails() {} ...@@ -957,10 +957,19 @@ PaymentsClient::UnmaskRequestDetails::~UnmaskRequestDetails() {}
PaymentsClient::UnmaskResponseDetails::UnmaskResponseDetails() {} PaymentsClient::UnmaskResponseDetails::UnmaskResponseDetails() {}
PaymentsClient::UnmaskResponseDetails::UnmaskResponseDetails( PaymentsClient::UnmaskResponseDetails::UnmaskResponseDetails(
const UnmaskResponseDetails& other) { const UnmaskResponseDetails& other) {
real_pan = other.real_pan; *this = other;
fido_creation_options = other.fido_creation_options.Clone();
} }
PaymentsClient::UnmaskResponseDetails::~UnmaskResponseDetails() {} PaymentsClient::UnmaskResponseDetails::~UnmaskResponseDetails() {}
PaymentsClient::UnmaskResponseDetails& PaymentsClient::UnmaskResponseDetails::
operator=(const PaymentsClient::UnmaskResponseDetails& other) {
real_pan = other.real_pan;
if (other.fido_creation_options.has_value()) {
fido_creation_options = other.fido_creation_options->Clone();
} else {
fido_creation_options.reset();
}
return *this;
}
PaymentsClient::OptChangeRequestDetails::OptChangeRequestDetails() {} PaymentsClient::OptChangeRequestDetails::OptChangeRequestDetails() {}
PaymentsClient::OptChangeRequestDetails::OptChangeRequestDetails( PaymentsClient::OptChangeRequestDetails::OptChangeRequestDetails(
......
...@@ -99,6 +99,7 @@ class PaymentsClient { ...@@ -99,6 +99,7 @@ class PaymentsClient {
UnmaskResponseDetails(); UnmaskResponseDetails();
UnmaskResponseDetails(const UnmaskResponseDetails& other); UnmaskResponseDetails(const UnmaskResponseDetails& other);
~UnmaskResponseDetails(); ~UnmaskResponseDetails();
UnmaskResponseDetails& operator=(const UnmaskResponseDetails& other);
UnmaskResponseDetails& with_real_pan(std::string r) { UnmaskResponseDetails& with_real_pan(std::string r) {
real_pan = r; real_pan = r;
...@@ -106,7 +107,7 @@ class PaymentsClient { ...@@ -106,7 +107,7 @@ class PaymentsClient {
} }
std::string real_pan; std::string real_pan;
base::Value fido_creation_options; base::Optional<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
......
...@@ -434,7 +434,7 @@ TEST_F(PaymentsClientTest, UnmaskSuccessViaCVCWithCreationOptions) { ...@@ -434,7 +434,7 @@ TEST_F(PaymentsClientTest, UnmaskSuccessViaCVCWithCreationOptions) {
EXPECT_EQ(AutofillClient::SUCCESS, result_); EXPECT_EQ(AutofillClient::SUCCESS, result_);
EXPECT_EQ("1234", unmask_response_details_->real_pan); EXPECT_EQ("1234", unmask_response_details_->real_pan);
EXPECT_EQ("google.com", EXPECT_EQ("google.com",
*unmask_response_details_->fido_creation_options.FindStringKey( *unmask_response_details_->fido_creation_options->FindStringKey(
"relying_party_id")); "relying_party_id"));
} }
......
...@@ -19,14 +19,11 @@ TestAuthenticationRequester::GetWeakPtr() { ...@@ -19,14 +19,11 @@ TestAuthenticationRequester::GetWeakPtr() {
} }
void TestAuthenticationRequester::OnCVCAuthenticationComplete( void TestAuthenticationRequester::OnCVCAuthenticationComplete(
bool did_succeed, const CreditCardCVCAuthenticator::CVCAuthenticationResponse& response) {
const CreditCard* card, did_succeed_ = response.did_succeed;
const base::string16& cvc,
base::Value creation_options) {
did_succeed_ = did_succeed;
if (did_succeed_) { if (did_succeed_) {
DCHECK(card); DCHECK(response.card);
number_ = card->number(); number_ = response.card->number();
} }
} }
......
...@@ -37,10 +37,8 @@ class TestAuthenticationRequester ...@@ -37,10 +37,8 @@ class TestAuthenticationRequester
// CreditCardCVCAuthenticator::Requester: // CreditCardCVCAuthenticator::Requester:
void OnCVCAuthenticationComplete( void OnCVCAuthenticationComplete(
bool did_succeed, const CreditCardCVCAuthenticator::CVCAuthenticationResponse& response)
const CreditCard* card = nullptr, 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