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

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

Issue 10630021: Modify experimental identity flow to display scope descriptions and details. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 8 years, 5 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 | Annotate | Revision Log
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 #include "chrome/browser/extensions/api/identity/identity_api.h" 5 #include "chrome/browser/extensions/api/identity/identity_api.h"
6 6
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "chrome/browser/extensions/extension_install_prompt.h"
8 #include "chrome/browser/extensions/extension_function_dispatcher.h" 9 #include "chrome/browser/extensions/extension_function_dispatcher.h"
10 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/signin/token_service.h" 11 #include "chrome/browser/signin/token_service.h"
10 #include "chrome/browser/signin/token_service_factory.h" 12 #include "chrome/browser/signin/token_service_factory.h"
11 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/tab_contents/tab_contents.h" 14 #include "chrome/browser/ui/tab_contents/tab_contents.h"
13 #include "chrome/common/extensions/extension.h" 15 #include "chrome/common/extensions/extension.h"
14 #include "googleurl/src/gurl.h" 16 #include "googleurl/src/gurl.h"
15 17
16 namespace extensions { 18 namespace extensions {
17 19
18 namespace { 20 namespace {
19 21
20 const char kInvalidClientId[] = "Invalid OAuth2 Client ID."; 22 const char kInvalidClientId[] = "Invalid OAuth2 Client ID.";
21 const char kInvalidScopes[] = "Invalid OAuth2 scopes."; 23 const char kInvalidScopes[] = "Invalid OAuth2 scopes.";
22 const char kInvalidRedirect[] = "Did not redirect to the right URL."; 24 const char kInvalidRedirect[] = "Did not redirect to the right URL.";
25 const char kAuthFailure[] = "OAuth2 request failed: ";
26 const char kGrantRevoked[] = "OAuth2 not granted or revoked.";
23 27
24 } // namespace 28 } // namespace
25 29
26 GetAuthTokenFunction::GetAuthTokenFunction() {} 30 GetAuthTokenFunction::GetAuthTokenFunction() {}
27 GetAuthTokenFunction::~GetAuthTokenFunction() {} 31 GetAuthTokenFunction::~GetAuthTokenFunction() {}
28 32
29 bool GetAuthTokenFunction::RunImpl() { 33 bool GetAuthTokenFunction::RunImpl() {
30 const Extension* extension = GetExtension(); 34 const Extension* extension = GetExtension();
31 Extension::OAuth2Info oauth2_info = extension->oauth2_info(); 35 Extension::OAuth2Info oauth2_info = extension->oauth2_info();
32 36
(...skipping 12 matching lines...) Expand all
45 TokenService* token_service = TokenServiceFactory::GetForProfile(profile()); 49 TokenService* token_service = TokenServiceFactory::GetForProfile(profile());
46 50
47 flow_.reset(new OAuth2MintTokenFlow( 51 flow_.reset(new OAuth2MintTokenFlow(
48 profile()->GetRequestContext(), 52 profile()->GetRequestContext(),
49 this, 53 this,
50 OAuth2MintTokenFlow::Parameters( 54 OAuth2MintTokenFlow::Parameters(
51 token_service->GetOAuth2LoginRefreshToken(), 55 token_service->GetOAuth2LoginRefreshToken(),
52 extension->id(), 56 extension->id(),
53 oauth2_info.client_id, 57 oauth2_info.client_id,
54 oauth2_info.scopes, 58 oauth2_info.scopes,
55 OAuth2MintTokenFlow::MODE_MINT_TOKEN_FORCE))); 59 ExtensionInstallPrompt::ShouldAutomaticallyApproveScopes() ?
60 OAuth2MintTokenFlow::MODE_MINT_TOKEN_FORCE :
61 OAuth2MintTokenFlow::MODE_MINT_TOKEN_NO_FORCE)));
56 flow_->Start(); 62 flow_->Start();
57 63
58 return true; 64 return true;
59 } 65 }
60 66
61 void GetAuthTokenFunction::OnMintTokenSuccess(const std::string& access_token) { 67 void GetAuthTokenFunction::OnMintTokenSuccess(const std::string& access_token) {
62 result_.reset(Value::CreateStringValue(access_token)); 68 result_.reset(Value::CreateStringValue(access_token));
63 SendResponse(true); 69 SendResponse(true);
64 Release(); // Balanced in RunImpl. 70 Release(); // Balanced in RunImpl.
65 } 71 }
66 72
67 void GetAuthTokenFunction::OnMintTokenFailure( 73 void GetAuthTokenFunction::OnMintTokenFailure(
68 const GoogleServiceAuthError& error) { 74 const GoogleServiceAuthError& error) {
69 error_ = error.ToString(); 75 error_ = std::string(kAuthFailure) + error.ToString();
70 SendResponse(false); 76 SendResponse(false);
71 Release(); // Balanced in RunImpl. 77 Release(); // Balanced in RunImpl.
72 } 78 }
79
80 void GetAuthTokenFunction::OnIssueAdviceSuccess(
81 const IssueAdviceInfo& issue_advice) {
82 // Existing grant was revoked and we used NO_FORCE, so we got info back
83 // instead.
84 error_ = kGrantRevoked;
85
86 // Remove the oauth2 scopes from the extension's granted permissions, if
87 // revoked server-side.
88 scoped_refptr<PermissionSet> scopes =
89 new PermissionSet(GetExtension()->GetActivePermissions()->scopes());
90 profile()->GetExtensionService()->extension_prefs()->RemoveGrantedPermissions(
91 GetExtension()->id(), scopes);
92
93 // TODO(estade): need to prompt the user for scope permissions.
94
95 SendResponse(false);
96 Release(); // Balanced in RunImpl.
97 }
73 98
74 LaunchWebAuthFlowFunction::LaunchWebAuthFlowFunction() {} 99 LaunchWebAuthFlowFunction::LaunchWebAuthFlowFunction() {}
75 LaunchWebAuthFlowFunction::~LaunchWebAuthFlowFunction() {} 100 LaunchWebAuthFlowFunction::~LaunchWebAuthFlowFunction() {}
76 101
77 bool LaunchWebAuthFlowFunction::RunImpl() { 102 bool LaunchWebAuthFlowFunction::RunImpl() {
78 DictionaryValue* arg = NULL; 103 DictionaryValue* arg = NULL;
79 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &arg)); 104 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &arg));
80 105
81 std::string url; 106 std::string url;
82 EXTENSION_FUNCTION_VALIDATE(arg->GetString("url", &url)); 107 EXTENSION_FUNCTION_VALIDATE(arg->GetString("url", &url));
(...skipping 19 matching lines...) Expand all
102 Release(); // Balanced in RunImpl. 127 Release(); // Balanced in RunImpl.
103 } 128 }
104 129
105 void LaunchWebAuthFlowFunction::OnAuthFlowFailure() { 130 void LaunchWebAuthFlowFunction::OnAuthFlowFailure() {
106 error_ = kInvalidRedirect; 131 error_ = kInvalidRedirect;
107 SendResponse(false); 132 SendResponse(false);
108 Release(); // Balanced in RunImpl. 133 Release(); // Balanced in RunImpl.
109 } 134 }
110 135
111 } // namespace extensions 136 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698