Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_IDENTITY_GAIA_WEB_AUTH_FLOW_H_ | |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_IDENTITY_GAIA_WEB_AUTH_FLOW_H_ | |
| 7 | |
| 8 #include "chrome/browser/extensions/api/identity/web_auth_flow.h" | |
| 9 #include "chrome/browser/signin/ubertoken_fetcher.h" | |
| 10 #include "chrome/browser/ui/host_desktop.h" | |
| 11 #include "chrome/common/extensions/api/identity/oauth2_manifest_handler.h" | |
| 12 | |
| 13 namespace extensions { | |
| 14 | |
| 15 // Implements a web-based OAuth2 scope approval dialog. This flow has | |
| 16 // four parts: | |
| 17 // 1. Fetch an ubertoken for the signed-in user. | |
| 18 // 2. Use the ubertoken to get session cookies using MergeSession. | |
| 19 // 3. Start the OAuth flow and wait for final redirect. | |
| 20 // 4. Parse results from the fragment component of the final redirect URI. | |
| 21 // | |
| 22 // The OAuth flow is a special version of the OAuth2 out-of-band flow | |
| 23 // where the final response page's title contains the | |
| 24 // redirect_uri. The redirect URI has an unusual format to prevent its | |
| 25 // use in other contexts. The scheme of the URI is a reversed version | |
| 26 // of the OAuth client ID, and the path starts with the Chrome | |
| 27 // extension ID. For example, an app with the OAuth client ID | |
| 28 // "32610281651.apps.googleusercontent.com" and a Chrome app ID | |
| 29 // "kbinjhdkhikmpjoejcfofghmjjpidcnj", would get redirected to: | |
| 30 // | |
| 31 // com.googleusercontent.apps.32610281651:/kbinjhdkhikmpjoejcfofghmjjpidcnj | |
| 32 // | |
| 33 // Arriving at this URI completes the flow. The last response from | |
| 34 // gaia does a JavaScript redirect to the special URI, but also | |
| 35 // includes the same URI in its title. The navigation to this URI gets | |
| 36 // filtered out because of its unusual protocol scheme, so | |
| 37 // GaiaWebAuthFlow pulls it out of the window title instead. | |
| 38 | |
| 39 class GaiaWebAuthFlow : public UbertokenConsumer, public WebAuthFlow::Delegate { | |
| 40 public: | |
| 41 enum Failure { | |
| 42 WINDOW_CLOSED, // Window closed by user. | |
| 43 INVALID_REDIRECT, // Redirect parse error. | |
| 44 SERVICE_AUTH_ERROR // Non-OAuth related authentication error | |
| 45 }; | |
| 46 | |
| 47 class Delegate { | |
| 48 public: | |
| 49 virtual void OnGaiaFlowFailure(Failure failure, | |
| 50 GoogleServiceAuthError service_error) = 0; | |
| 51 virtual void OnGaiaFlowCompleted(const std::string& access_token, | |
| 52 const std::string& expiration, | |
| 53 const std::string& error) = 0; | |
|
asargent_no_longer_on_chrome
2013/05/16 21:39:20
nit: It seems slightly unexpected that there are s
Michael Courage
2013/05/16 22:44:08
I was thinking of these errors as special because
| |
| 54 }; | |
| 55 | |
| 56 GaiaWebAuthFlow(Delegate* delegate, | |
| 57 Profile* profile, | |
| 58 chrome::HostDesktopType host_desktop_type, | |
| 59 const std::string& extension_id, | |
| 60 const OAuth2Info& oauth2_info); | |
| 61 virtual ~GaiaWebAuthFlow(); | |
| 62 | |
| 63 // Starts the flow by fetching an ubertoken. Can override for testing. | |
| 64 virtual void Start(); | |
| 65 | |
| 66 // UbertokenConsumer implementation: | |
| 67 virtual void OnUbertokenSuccess(const std::string& token) OVERRIDE; | |
| 68 virtual void OnUbertokenFailure(const GoogleServiceAuthError& error) OVERRIDE; | |
| 69 | |
| 70 // WebAuthFlow::Delegate implementation. | |
| 71 virtual void OnAuthFlowFailure(WebAuthFlow::Failure failure) OVERRIDE; | |
| 72 virtual void OnAuthFlowURLChange(const GURL& redirect_url) OVERRIDE; | |
| 73 virtual void OnAuthFlowTitleChange(const std::string& title) OVERRIDE; | |
| 74 | |
| 75 private: | |
| 76 // Creates a WebAuthFlow, which will navigate to |url|. Can override | |
| 77 // for testing. Used to kick off the MergeSession (step #2). | |
| 78 virtual scoped_ptr<WebAuthFlow> CreateWebAuthFlow(GURL url); | |
| 79 | |
| 80 Delegate* delegate_; | |
| 81 Profile* profile_; | |
| 82 chrome::HostDesktopType host_desktop_type_; | |
| 83 std::string redirect_scheme_; | |
| 84 std::string redirect_path_prefix_; | |
| 85 std::string auth_url_; | |
|
asargent_no_longer_on_chrome
2013/05/16 21:39:20
Any reason you aren't using a GURL here for |auth_
Michael Courage
2013/05/16 22:44:08
Done. No crazy URLs here.
| |
| 86 scoped_ptr<UbertokenFetcher> ubertoken_fetcher_; | |
| 87 scoped_ptr<WebAuthFlow> web_flow_; | |
| 88 | |
| 89 DISALLOW_COPY_AND_ASSIGN(GaiaWebAuthFlow); | |
| 90 }; | |
| 91 | |
| 92 } // extensions | |
| 93 | |
| 94 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_GAIA_WEB_AUTH_FLOW_H_ | |
| OLD | NEW |