Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(564)

Side by Side Diff: chrome/browser/extensions/api/identity/identity_api.h

Issue 15148007: Identity API: web-based scope approval dialogs for getAuthToken (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: better protocol description Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "chrome/browser/extensions/api/identity/gaia_web_auth_flow.h"
14 #include "chrome/browser/extensions/api/identity/identity_mint_queue.h" 15 #include "chrome/browser/extensions/api/identity/identity_mint_queue.h"
15 #include "chrome/browser/extensions/api/identity/identity_signin_flow.h" 16 #include "chrome/browser/extensions/api/identity/identity_signin_flow.h"
16 #include "chrome/browser/extensions/api/identity/web_auth_flow.h" 17 #include "chrome/browser/extensions/api/identity/web_auth_flow.h"
17 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h" 18 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h"
18 #include "chrome/browser/extensions/extension_function.h" 19 #include "chrome/browser/extensions/extension_function.h"
19 #include "chrome/browser/extensions/extension_install_prompt.h"
20 #include "chrome/browser/signin/signin_global_error.h" 20 #include "chrome/browser/signin/signin_global_error.h"
21 #include "google_apis/gaia/oauth2_mint_token_flow.h" 21 #include "google_apis/gaia/oauth2_mint_token_flow.h"
22 22
23 class GetAuthTokenFunctionTest; 23 class GetAuthTokenFunctionTest;
24 class MockGetAuthTokenFunction; 24 class MockGetAuthTokenFunction;
25 class GoogleServiceAuthError; 25 class GoogleServiceAuthError;
26 class Profile; 26 class Profile;
27 class SigninManagerBase; 27 class SigninManagerBase;
28 28
29 namespace extensions { 29 namespace extensions {
(...skipping 21 matching lines...) Expand all
51 // 51 //
52 // The interactive flow presents a scope approval dialog to the 52 // The interactive flow presents a scope approval dialog to the
53 // user. If the user approves the request, a grant will be recorded on 53 // user. If the user approves the request, a grant will be recorded on
54 // the server, and an access token will be returned to the caller. 54 // the server, and an access token will be returned to the caller.
55 // 55 //
56 // In some cases we need to display a sign-in dialog. Normally the 56 // In some cases we need to display a sign-in dialog. Normally the
57 // profile will be signed in already, but if it turns out we need a 57 // profile will be signed in already, but if it turns out we need a
58 // new login token, there is a sign-in flow. If that flow completes 58 // new login token, there is a sign-in flow. If that flow completes
59 // successfully, getAuthToken proceeds to the non-interactive flow. 59 // successfully, getAuthToken proceeds to the non-interactive flow.
60 class IdentityGetAuthTokenFunction : public AsyncExtensionFunction, 60 class IdentityGetAuthTokenFunction : public AsyncExtensionFunction,
61 public ExtensionInstallPrompt::Delegate, 61 public GaiaWebAuthFlow::Delegate,
62 public IdentityMintRequestQueue::Request, 62 public IdentityMintRequestQueue::Request,
63 public OAuth2MintTokenFlow::Delegate, 63 public OAuth2MintTokenFlow::Delegate,
64 public IdentitySigninFlow::Delegate { 64 public IdentitySigninFlow::Delegate {
65 public: 65 public:
66 DECLARE_EXTENSION_FUNCTION("identity.getAuthToken", 66 DECLARE_EXTENSION_FUNCTION("identity.getAuthToken",
67 EXPERIMENTAL_IDENTITY_GETAUTHTOKEN); 67 EXPERIMENTAL_IDENTITY_GETAUTHTOKEN);
68 68
69 IdentityGetAuthTokenFunction(); 69 IdentityGetAuthTokenFunction();
70 70
71 protected: 71 protected:
(...skipping 23 matching lines...) Expand all
95 int time_to_live) OVERRIDE; 95 int time_to_live) OVERRIDE;
96 virtual void OnMintTokenFailure( 96 virtual void OnMintTokenFailure(
97 const GoogleServiceAuthError& error) OVERRIDE; 97 const GoogleServiceAuthError& error) OVERRIDE;
98 virtual void OnIssueAdviceSuccess( 98 virtual void OnIssueAdviceSuccess(
99 const IssueAdviceInfo& issue_advice) OVERRIDE; 99 const IssueAdviceInfo& issue_advice) OVERRIDE;
100 100
101 // IdentitySigninFlow::Delegate implementation: 101 // IdentitySigninFlow::Delegate implementation:
102 virtual void SigninSuccess(const std::string& token) OVERRIDE; 102 virtual void SigninSuccess(const std::string& token) OVERRIDE;
103 virtual void SigninFailed() OVERRIDE; 103 virtual void SigninFailed() OVERRIDE;
104 104
105 // ExtensionInstallPrompt::Delegate implementation: 105 // GaiaWebAuthFlow::Delegate implementation:
106 virtual void InstallUIProceed() OVERRIDE; 106 virtual void OnGaiaFlowFailure(GaiaWebAuthFlow::Failure failure,
107 virtual void InstallUIAbort(bool user_initiated) OVERRIDE; 107 GoogleServiceAuthError service_error) OVERRIDE;
108 virtual void OnGaiaFlowCompleted(const std::string& token,
109 const std::string& expiration,
110 const std::string& error) OVERRIDE;
108 111
109 // Starts a mint token request to GAIA. 112 // Starts a mint token request to GAIA.
110 void StartGaiaRequest(OAuth2MintTokenFlow::Mode mode); 113 void StartGaiaRequest(OAuth2MintTokenFlow::Mode mode);
111 114
112 // Methods for invoking UI. Overridable for testing. 115 // Methods for invoking UI. Overridable for testing.
113 virtual void ShowLoginPopup(); 116 virtual void ShowLoginPopup();
114 virtual void ShowOAuthApprovalDialog(const IssueAdviceInfo& issue_advice); 117 virtual void ShowOAuthApprovalDialog(const IssueAdviceInfo& issue_advice);
115 // Caller owns the returned instance. 118 // Caller owns the returned instance.
116 virtual OAuth2MintTokenFlow* CreateMintTokenFlow( 119 virtual OAuth2MintTokenFlow* CreateMintTokenFlow(
117 OAuth2MintTokenFlow::Mode mode); 120 OAuth2MintTokenFlow::Mode mode);
118 121
119 // Checks if there is a master login token to mint tokens for the extension. 122 // Checks if there is a master login token to mint tokens for the extension.
120 virtual bool HasLoginToken() const; 123 virtual bool HasLoginToken() const;
121 124
125 // Maps OAuth2 protocol errors to an error message.
126 std::string MapOAuth2ErrorToDescription(const std::string& error);
127
122 bool should_prompt_for_scopes_; 128 bool should_prompt_for_scopes_;
123 IdentityMintRequestQueue::MintType mint_token_flow_type_; 129 IdentityMintRequestQueue::MintType mint_token_flow_type_;
124 scoped_ptr<OAuth2MintTokenFlow> mint_token_flow_; 130 scoped_ptr<OAuth2MintTokenFlow> mint_token_flow_;
125 std::string refresh_token_; 131 std::string refresh_token_;
126 bool should_prompt_for_signin_; 132 bool should_prompt_for_signin_;
127 133
128 // When launched in interactive mode, and if there is no existing grant, 134 // When launched in interactive mode, and if there is no existing grant,
129 // a permissions prompt will be popped up to the user. 135 // a permissions prompt will be popped up to the user.
130 IssueAdviceInfo issue_advice_; 136 IssueAdviceInfo issue_advice_;
131 scoped_ptr<ExtensionInstallPrompt> install_ui_; 137 scoped_ptr<GaiaWebAuthFlow> web_auth_flow_;
Roger Tawa OOO till Jul 10th 2013/05/16 16:06:15 Maybe call this |gaia_web_auth_flow_| instead to d
Michael Courage 2013/05/16 20:39:02 Done.
132 scoped_ptr<IdentitySigninFlow> signin_flow_; 138 scoped_ptr<IdentitySigninFlow> signin_flow_;
133 }; 139 };
134 140
135 class IdentityRemoveCachedAuthTokenFunction : public SyncExtensionFunction { 141 class IdentityRemoveCachedAuthTokenFunction : public SyncExtensionFunction {
136 public: 142 public:
137 DECLARE_EXTENSION_FUNCTION("identity.removeCachedAuthToken", 143 DECLARE_EXTENSION_FUNCTION("identity.removeCachedAuthToken",
138 EXPERIMENTAL_IDENTITY_REMOVECACHEDAUTHTOKEN) 144 EXPERIMENTAL_IDENTITY_REMOVECACHEDAUTHTOKEN)
139 IdentityRemoveCachedAuthTokenFunction(); 145 IdentityRemoveCachedAuthTokenFunction();
140 146
141 protected: 147 protected:
(...skipping 14 matching lines...) Expand all
156 // Tests may override extension_id. 162 // Tests may override extension_id.
157 void InitFinalRedirectURLPrefixForTest(const std::string& extension_id); 163 void InitFinalRedirectURLPrefixForTest(const std::string& extension_id);
158 164
159 private: 165 private:
160 virtual ~IdentityLaunchWebAuthFlowFunction(); 166 virtual ~IdentityLaunchWebAuthFlowFunction();
161 virtual bool RunImpl() OVERRIDE; 167 virtual bool RunImpl() OVERRIDE;
162 168
163 // WebAuthFlow::Delegate implementation. 169 // WebAuthFlow::Delegate implementation.
164 virtual void OnAuthFlowFailure(WebAuthFlow::Failure failure) OVERRIDE; 170 virtual void OnAuthFlowFailure(WebAuthFlow::Failure failure) OVERRIDE;
165 virtual void OnAuthFlowURLChange(const GURL& redirect_url) OVERRIDE; 171 virtual void OnAuthFlowURLChange(const GURL& redirect_url) OVERRIDE;
172 virtual void OnAuthFlowTitleChange(const std::string& title) OVERRIDE {}
166 173
167 // Helper to initialize final URL prefix. 174 // Helper to initialize final URL prefix.
168 void InitFinalRedirectURLPrefix(const std::string& extension_id); 175 void InitFinalRedirectURLPrefix(const std::string& extension_id);
169 176
170 scoped_ptr<WebAuthFlow> auth_flow_; 177 scoped_ptr<WebAuthFlow> auth_flow_;
171 GURL final_url_prefix_; 178 GURL final_url_prefix_;
172 }; 179 };
173 180
174 class IdentityTokenCacheValue { 181 class IdentityTokenCacheValue {
175 public: 182 public:
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 IdentityMintRequestQueue mint_queue_; 268 IdentityMintRequestQueue mint_queue_;
262 std::map<TokenCacheKey, IdentityTokenCacheValue> token_cache_; 269 std::map<TokenCacheKey, IdentityTokenCacheValue> token_cache_;
263 }; 270 };
264 271
265 template <> 272 template <>
266 void ProfileKeyedAPIFactory<IdentityAPI>::DeclareFactoryDependencies(); 273 void ProfileKeyedAPIFactory<IdentityAPI>::DeclareFactoryDependencies();
267 274
268 } // namespace extensions 275 } // namespace extensions
269 276
270 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ 277 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698