1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_EXTENSIONS_API_IDENTITY_GAIA_REMOTE_CONSENT_FLOW_H_
#define CHROME_BROWSER_EXTENSIONS_API_IDENTITY_GAIA_REMOTE_CONSENT_FLOW_H_
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/extensions/api/identity/extension_token_key.h"
#include "chrome/browser/extensions/api/identity/web_auth_flow.h"
#include "components/signin/public/identity_manager/accounts_cookie_mutator.h"
#include "content/public/browser/storage_partition.h"
#include "google_apis/gaia/oauth2_mint_token_flow.h"
#include "net/cookies/cookie_access_result.h"
namespace extensions {
class GaiaRemoteConsentFlow : public WebAuthFlow::Delegate {
public:
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
// LINT.IfChange(GaiaRemoteConsentFlowResult)
enum Failure {
NONE = 0,
WINDOW_CLOSED = 1,
LOAD_FAILED = 2,
// Deprecated:
// SET_ACCOUNTS_IN_COOKIE_FAILED = 3,
INVALID_CONSENT_RESULT = 4,
NO_GRANT = 5,
// Deprecated:
// USER_NAVIGATED_AWAY = 6,
CANNOT_CREATE_WINDOW = 7,
SET_RESOLUTION_COOKIES_FAILED = 8,
kMaxValue = SET_RESOLUTION_COOKIES_FAILED
};
// LINT.ThenChange(//tools/metrics/histograms/metadata/signin/enums.xml:GaiaRemoteConsentFlowResult)
class Delegate {
public:
virtual ~Delegate();
// Called when the flow ends without getting the user consent.
virtual void OnGaiaRemoteConsentFlowFailed(Failure failure) = 0;
// Called when the user gives the approval via the OAuth2 remote consent
// screen.
virtual void OnGaiaRemoteConsentFlowApproved(
const std::string& consent_result,
const GaiaId& gaia_id) = 0;
};
GaiaRemoteConsentFlow(Delegate* delegate,
Profile* profile,
const ExtensionTokenKey& token_key,
const RemoteConsentResolutionData& resolution_data,
bool user_gesture);
~GaiaRemoteConsentFlow() override;
GaiaRemoteConsentFlow(const GaiaRemoteConsentFlow& other) = delete;
GaiaRemoteConsentFlow& operator=(const GaiaRemoteConsentFlow& other) = delete;
// Starts the flow by setting accounts in cookie.
void Start();
void Stop();
// Handles `consent_result` value when using either a Browser Tab or an App
// Window to display the Auth page.
void ReactToConsentResult(const std::string& consent_result);
// WebAuthFlow::Delegate:
void OnAuthFlowFailure(WebAuthFlow::Failure failure) override;
void OnNavigationFinished(
content::NavigationHandle* navigation_handle) override;
void SetWebAuthFlowForTesting(std::unique_ptr<WebAuthFlow> web_auth_flow);
WebAuthFlow* GetWebAuthFlowForTesting() const;
private:
void OnResolutionDataCookiesSet(
const std::vector<net::CookieAccessResult>& cookie_set_result);
void GaiaRemoteConsentFlowFailed(Failure failure);
void DetachWebAuthFlow();
network::mojom::CookieManager* GetCookieManagerForPartition();
const raw_ptr<Delegate> delegate_;
raw_ptr<Profile> profile_;
const RemoteConsentResolutionData resolution_data_;
const bool user_gesture_;
std::unique_ptr<WebAuthFlow> web_flow_;
bool web_flow_started_;
base::WeakPtrFactory<GaiaRemoteConsentFlow> weak_factory{this};
};
} // namespace extensions
#endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_GAIA_REMOTE_CONSENT_FLOW_H_
|