Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "google_apis/gaia/gaia_urls.h" | 5 #include "google_apis/gaia/gaia_urls.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "google_apis/gaia/gaia_switches.h" | 8 #include "google_apis/gaia/gaia_switches.h" |
| 9 #include "google_apis/google_api_keys.h" | 9 #include "google_apis/google_api_keys.h" |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 // Gaia service constants | 13 // Gaia service constants |
| 14 const char kDefaultGaiaBaseUrl[] = "accounts.google.com"; | 14 const char kDefaultGaiaBaseUrl[] = "accounts.google.com"; |
| 15 const char kDefaultGoogleApisBaseUrl[] = "www.googleapis.com"; | |
| 15 const char kCaptchaUrlPrefixSuffix[] = "/"; | 16 const char kCaptchaUrlPrefixSuffix[] = "/"; |
| 17 | |
| 18 // API calls from accounts.google.com | |
| 16 const char kClientLoginUrlSuffix[] = "/ClientLogin"; | 19 const char kClientLoginUrlSuffix[] = "/ClientLogin"; |
| 17 const char kServiceLoginUrlSuffix[] = "/ServiceLogin"; | 20 const char kServiceLoginUrlSuffix[] = "/ServiceLogin"; |
| 18 const char kIssueAuthTokenUrlSuffix[] = "/IssueAuthToken"; | 21 const char kIssueAuthTokenUrlSuffix[] = "/IssueAuthToken"; |
| 19 const char kGetUserInfoUrlSuffix[] = "/GetUserInfo"; | 22 const char kGetUserInfoUrlSuffix[] = "/GetUserInfo"; |
| 20 const char kTokenAuthUrlSuffix[] = "/TokenAuth"; | 23 const char kTokenAuthUrlSuffix[] = "/TokenAuth"; |
| 21 const char kMergeSessionUrlSuffix[] = "/MergeSession"; | 24 const char kMergeSessionUrlSuffix[] = "/MergeSession"; |
| 22 | 25 const char kOAuth1LoginScopeSuffix[] = "/OAuthLogin"; |
| 23 const char kOAuthGetAccessTokenUrlSuffix[] = "/OAuthGetAccessToken"; | 26 const char kOAuthGetAccessTokenUrlSuffix[] = "/OAuthGetAccessToken"; |
| 24 const char kOAuthWrapBridgeUrlSuffix[] = "/OAuthWrapBridge"; | 27 const char kOAuthWrapBridgeUrlSuffix[] = "/OAuthWrapBridge"; |
| 25 const char kOAuth1LoginUrlSuffix[] = "/OAuthLogin"; | 28 const char kOAuth1LoginUrlSuffix[] = "/OAuthLogin"; |
| 26 const char kOAuthRevokeTokenUrlSuffix[] = "/AuthSubRevokeToken"; | 29 const char kOAuthRevokeTokenUrlSuffix[] = "/AuthSubRevokeToken"; |
| 27 | 30 |
| 28 // Federated login constants | 31 // API calls from accounts.google.com (LSO) |
| 29 const char kDefaultFederatedLoginHost[] = "www.google.com"; | |
| 30 const char kDefaultFederatedLoginPath[] = "/accounts"; | |
| 31 const char kGetOAuthTokenUrlSuffix[] = "/o/oauth/GetOAuthToken/"; | 32 const char kGetOAuthTokenUrlSuffix[] = "/o/oauth/GetOAuthToken/"; |
| 33 const char kClientLoginToOAuth2UrlSuffix[] = "/o/oauth2/programmatic_auth"; | |
| 34 const char kOAuth2TokenUrlSuffix[] = "/o/oauth2/token"; | |
| 35 const char kClientOAuthUrlSuffix[] = "/ClientOAuth"; | |
| 32 | 36 |
| 33 const char kClientLoginToOAuth2Url[] = | 37 // API calls from www.googleapis.com |
| 34 "https://accounts.google.com/o/oauth2/programmatic_auth"; | 38 const char kOAuth2IssueTokenUrlSuffix[] = "/oauth2/v2/IssueToken"; |
| 35 const char kOAuth2TokenUrl[] = | 39 const char kOAuthUserInfoUrlSuffix[] = "/oauth2/v1/userinfo"; |
| 36 "https://accounts.google.com/o/oauth2/token"; | 40 const char kOAuthWrapBridgeUserInfoScopeUrlSuffix[] = "/auth/userinfo.email"; |
| 37 const char kOAuth2IssueTokenUrl[] = | |
| 38 "https://www.googleapis.com/oauth2/v2/IssueToken"; | |
| 39 const char kOAuth1LoginScope[] = | |
| 40 "https://www.google.com/accounts/OAuthLogin"; | |
| 41 const char kOAuthUserInfoUrl[] = | |
| 42 "https://www.googleapis.com/oauth2/v1/userinfo"; | |
| 43 | |
| 44 | 41 |
| 45 void GetSwitchValueWithDefault(const char* switch_value, | 42 void GetSwitchValueWithDefault(const char* switch_value, |
| 46 const char* default_value, | 43 const char* default_value, |
| 47 std::string* output_value) { | 44 std::string* output_value) { |
| 48 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 45 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 49 if (command_line->HasSwitch(switch_value)) { | 46 if (command_line->HasSwitch(switch_value)) { |
| 50 *output_value = command_line->GetSwitchValueASCII(switch_value); | 47 *output_value = command_line->GetSwitchValueASCII(switch_value); |
| 51 } else { | 48 } else { |
| 52 *output_value = default_value; | 49 *output_value = default_value; |
| 53 } | 50 } |
| 54 } | 51 } |
| 55 | 52 |
| 56 } // namespace | 53 } // namespace |
| 57 | 54 |
| 58 GaiaUrls* GaiaUrls::GetInstance() { | 55 GaiaUrls* GaiaUrls::GetInstance() { |
| 59 return Singleton<GaiaUrls>::get(); | 56 return Singleton<GaiaUrls>::get(); |
| 60 } | 57 } |
| 61 | 58 |
| 62 GaiaUrls::GaiaUrls() { | 59 GaiaUrls::GaiaUrls() { |
| 63 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 60 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 64 std::string host_base; | 61 std::string host_base; |
| 65 GetSwitchValueWithDefault(switches::kGaiaHost, kDefaultGaiaBaseUrl, | 62 GetSwitchValueWithDefault(switches::kGaiaHost, kDefaultGaiaBaseUrl, |
| 66 &host_base); | 63 &host_base); |
| 67 | 64 |
| 65 std::string lso_base; | |
| 66 GetSwitchValueWithDefault(switches::kLsoHost, kDefaultGaiaBaseUrl, | |
| 67 &lso_base); | |
| 68 | |
| 69 std::string google_apis_base; | |
| 70 GetSwitchValueWithDefault(switches::kGoogleApisHost, kDefaultGoogleApisBaseUrl , | |
|
xiyuan
2013/01/07 23:16:46
nit: 80 cols
zel
2013/01/08 01:13:08
Done.
| |
| 71 &google_apis_base); | |
| 72 | |
| 68 captcha_url_prefix_ = "http://" + host_base + kCaptchaUrlPrefixSuffix; | 73 captcha_url_prefix_ = "http://" + host_base + kCaptchaUrlPrefixSuffix; |
| 69 gaia_origin_url_ = "https://" + host_base; | 74 gaia_origin_url_ = "https://" + host_base; |
| 75 lso_origin_url_ = "https://" + lso_base; | |
| 76 google_apis_origin_url_ = "https://" + google_apis_base; | |
| 70 std::string gaia_url_base = gaia_origin_url_; | 77 std::string gaia_url_base = gaia_origin_url_; |
| 71 if (command_line->HasSwitch(switches::kGaiaUrlPath)) { | 78 if (command_line->HasSwitch(switches::kGaiaUrlPath)) { |
| 72 std::string path = | 79 std::string path = |
| 73 command_line->GetSwitchValueASCII(switches::kGaiaUrlPath); | 80 command_line->GetSwitchValueASCII(switches::kGaiaUrlPath); |
| 74 if (!path.empty()) { | 81 if (!path.empty()) { |
| 75 if (path[0] != '/') | 82 if (path[0] != '/') |
| 76 gaia_url_base.append("/"); | 83 gaia_url_base.append("/"); |
| 77 | 84 |
| 78 gaia_url_base.append(path); | 85 gaia_url_base.append(path); |
| 79 } | 86 } |
| 80 } | 87 } |
| 81 | 88 |
| 89 | |
| 90 oauth2_chrome_client_id_ = | |
| 91 google_apis::GetOAuth2ClientID(google_apis::CLIENT_MAIN); | |
| 92 oauth2_chrome_client_secret_ = | |
| 93 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_MAIN); | |
| 94 | |
| 95 // URLs from accounts.google.com. | |
| 96 gaia_login_form_realm_ = gaia_url_base + "/"; | |
| 82 client_login_url_ = gaia_url_base + kClientLoginUrlSuffix; | 97 client_login_url_ = gaia_url_base + kClientLoginUrlSuffix; |
| 83 service_login_url_ = gaia_url_base + kServiceLoginUrlSuffix; | 98 service_login_url_ = gaia_url_base + kServiceLoginUrlSuffix; |
| 84 issue_auth_token_url_ = gaia_url_base + kIssueAuthTokenUrlSuffix; | 99 issue_auth_token_url_ = gaia_url_base + kIssueAuthTokenUrlSuffix; |
| 85 get_user_info_url_ = gaia_url_base + kGetUserInfoUrlSuffix; | 100 get_user_info_url_ = gaia_url_base + kGetUserInfoUrlSuffix; |
| 86 token_auth_url_ = gaia_url_base + kTokenAuthUrlSuffix; | 101 token_auth_url_ = gaia_url_base + kTokenAuthUrlSuffix; |
| 87 merge_session_url_ = gaia_url_base + kMergeSessionUrlSuffix; | 102 merge_session_url_ = gaia_url_base + kMergeSessionUrlSuffix; |
| 88 get_oauth_token_url_ = gaia_url_base + kGetOAuthTokenUrlSuffix; | |
| 89 oauth_get_access_token_url_ = gaia_url_base + | 103 oauth_get_access_token_url_ = gaia_url_base + |
| 90 kOAuthGetAccessTokenUrlSuffix; | 104 kOAuthGetAccessTokenUrlSuffix; |
| 91 oauth_wrap_bridge_url_ = gaia_url_base + kOAuthWrapBridgeUrlSuffix; | 105 oauth_wrap_bridge_url_ = gaia_url_base + kOAuthWrapBridgeUrlSuffix; |
| 92 oauth_revoke_token_url_ = gaia_url_base + kOAuthRevokeTokenUrlSuffix; | 106 oauth_revoke_token_url_ = gaia_url_base + kOAuthRevokeTokenUrlSuffix; |
| 93 oauth1_login_url_ = gaia_url_base + kOAuth1LoginUrlSuffix; | 107 oauth1_login_url_ = gaia_url_base + kOAuth1LoginUrlSuffix; |
| 108 client_oauth_url_ = gaia_url_base + kClientOAuthUrlSuffix; | |
| 94 | 109 |
| 110 // URLs from accounts.google.com (LSO). | |
| 111 get_oauth_token_url_ = lso_origin_url_ + kGetOAuthTokenUrlSuffix; | |
| 112 std::string client_login_to_oauth2_url = lso_origin_url_ + | |
| 113 kClientLoginToOAuth2UrlSuffix; | |
| 114 std::string oauth2_token_url = lso_origin_url_ + kOAuth2TokenUrlSuffix; | |
| 115 | |
| 116 // URLs from www.googleapis.com. | |
| 117 oauth_wrap_bridge_user_info_scope_ = google_apis_origin_url_ + | |
| 118 kOAuthWrapBridgeUserInfoScopeUrlSuffix; | |
| 119 std::string oauth2_issue_token_url = google_apis_origin_url_ + | |
| 120 kOAuth2IssueTokenUrlSuffix; | |
| 121 std::string oauth_user_info_url = google_apis_origin_url_ + | |
| 122 kOAuthUserInfoUrlSuffix; | |
| 123 | |
| 124 // TODO(zelidrag): Get rid of all these switches since all URLs should be | |
| 125 // controlled only with --gaia-host, --lso-host and --google-apis-host. | |
| 95 GetSwitchValueWithDefault(switches::kOAuth1LoginScope, | 126 GetSwitchValueWithDefault(switches::kOAuth1LoginScope, |
| 96 kOAuth1LoginScope, | 127 oauth1_login_url_.c_str(), |
| 97 &oauth1_login_scope_); | 128 &oauth1_login_scope_); |
| 98 | |
| 99 // TODO(joaodasilva): these aren't configurable for now, but are managed here | |
| 100 // so that users of Gaia URLs don't have to use static constants. | |
| 101 // http://crbug.com/97126 | |
| 102 oauth_wrap_bridge_user_info_scope_ = | |
| 103 "https://www.googleapis.com/auth/userinfo.email"; | |
| 104 client_oauth_url_ = "https://accounts.google.com/ClientOAuth"; | |
| 105 | |
| 106 oauth2_chrome_client_id_ = | |
| 107 google_apis::GetOAuth2ClientID(google_apis::CLIENT_MAIN); | |
| 108 oauth2_chrome_client_secret_ = | |
| 109 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_MAIN); | |
| 110 | |
| 111 GetSwitchValueWithDefault(switches::kClientLoginToOAuth2Url, | 129 GetSwitchValueWithDefault(switches::kClientLoginToOAuth2Url, |
| 112 kClientLoginToOAuth2Url, | 130 client_login_to_oauth2_url.c_str(), |
| 113 &client_login_to_oauth2_url_); | 131 &client_login_to_oauth2_url_); |
| 114 GetSwitchValueWithDefault(switches::kOAuth2TokenUrl, | 132 GetSwitchValueWithDefault(switches::kOAuth2TokenUrl, |
| 115 kOAuth2TokenUrl, | 133 oauth2_token_url.c_str(), |
| 116 &oauth2_token_url_); | 134 &oauth2_token_url_); |
| 117 GetSwitchValueWithDefault(switches::kOAuth2IssueTokenUrl, | 135 GetSwitchValueWithDefault(switches::kOAuth2IssueTokenUrl, |
| 118 kOAuth2IssueTokenUrl, | 136 oauth2_issue_token_url.c_str(), |
| 119 &oauth2_issue_token_url_); | 137 &oauth2_issue_token_url_); |
| 120 GetSwitchValueWithDefault(switches::kOAuthUserInfoUrl, | 138 GetSwitchValueWithDefault(switches::kOAuthUserInfoUrl, |
| 121 kOAuthUserInfoUrl, | 139 oauth_user_info_url.c_str(), |
| 122 &oauth_user_info_url_); | 140 &oauth_user_info_url_); |
| 123 | |
| 124 gaia_login_form_realm_ = "https://accounts.google.com/"; | |
| 125 } | 141 } |
| 126 | 142 |
| 127 GaiaUrls::~GaiaUrls() { | 143 GaiaUrls::~GaiaUrls() { |
| 128 } | 144 } |
| 129 | 145 |
| 130 const std::string& GaiaUrls::captcha_url_prefix() { | 146 const std::string& GaiaUrls::captcha_url_prefix() { |
| 131 return captcha_url_prefix_; | 147 return captcha_url_prefix_; |
| 132 } | 148 } |
| 133 | 149 |
| 134 const std::string& GaiaUrls::gaia_origin_url() { | 150 const std::string& GaiaUrls::gaia_origin_url() { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 } | 228 } |
| 213 | 229 |
| 214 const std::string& GaiaUrls::oauth2_issue_token_url() { | 230 const std::string& GaiaUrls::oauth2_issue_token_url() { |
| 215 return oauth2_issue_token_url_; | 231 return oauth2_issue_token_url_; |
| 216 } | 232 } |
| 217 | 233 |
| 218 | 234 |
| 219 const std::string& GaiaUrls::gaia_login_form_realm() { | 235 const std::string& GaiaUrls::gaia_login_form_realm() { |
| 220 return gaia_login_form_realm_; | 236 return gaia_login_form_realm_; |
| 221 } | 237 } |
| OLD | NEW |