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 3 // found in the LICENSE file. 4 5 #include "google_apis/gaia/gaia_urls.h" 6 7 #include "base/command_line.h" 8 #include "base/logging.h" 9 #include "google_apis/gaia/gaia_switches.h" 10 #include "google_apis/google_api_keys.h" 11 12 namespace { 13 14 // Gaia service constants 15 const char kDefaultGaiaUrl[] = "https://accounts.google.com"; 16 const char kDefaultGoogleApisBaseUrl[] = "https://www.googleapis.com"; 17 18 // API calls from accounts.google.com 19 const char kClientLoginUrlSuffix[] = "ClientLogin"; 20 const char kServiceLoginUrlSuffix[] = "ServiceLogin"; 21 const char kServiceLoginAuthUrlSuffix[] = "ServiceLoginAuth"; 22 const char kServiceLogoutUrlSuffix[] = "Logout"; 23 const char kIssueAuthTokenUrlSuffix[] = "IssueAuthToken"; 24 const char kGetUserInfoUrlSuffix[] = "GetUserInfo"; 25 const char kTokenAuthUrlSuffix[] = "TokenAuth"; 26 const char kMergeSessionUrlSuffix[] = "MergeSession"; 27 const char kOAuthGetAccessTokenUrlSuffix[] = "OAuthGetAccessToken"; 28 const char kOAuthWrapBridgeUrlSuffix[] = "OAuthWrapBridge"; 29 const char kOAuth1LoginUrlSuffix[] = "OAuthLogin"; 30 const char kOAuthRevokeTokenUrlSuffix[] = "AuthSubRevokeToken"; 31 const char kListAccountsSuffix[] = "ListAccounts?json=standard"; 32 const char kEmbeddedSigninSuffix[] = "EmbeddedSignIn"; 33 const char kAddAccountSuffix[] = "AddSession"; 34 35 // API calls from accounts.google.com (LSO) 36 const char kGetOAuthTokenUrlSuffix[] = "o/oauth/GetOAuthToken/"; 37 const char kClientLoginToOAuth2UrlSuffix[] = "o/oauth2/programmatic_auth"; 38 const char kOAuth2AuthUrlSuffix[] = "o/oauth2/auth"; 39 const char kOAuth2RevokeUrlSuffix[] = "o/oauth2/revoke"; 40 const char kOAuth2TokenUrlSuffix[] = "o/oauth2/token"; 41 42 // API calls from www.googleapis.com 43 const char kOAuth2IssueTokenUrlSuffix[] = "oauth2/v2/IssueToken"; 44 const char kOAuth2TokenInfoUrlSuffix[] = "oauth2/v2/tokeninfo"; 45 const char kOAuthUserInfoUrlSuffix[] = "oauth2/v1/userinfo"; 46 47 void GetSwitchValueWithDefault(const char* switch_value, 48 const char* default_value, 49 std::string* output_value) { 50 CommandLine* command_line = CommandLine::ForCurrentProcess(); 51 if (command_line->HasSwitch(switch_value)) { 52 *output_value = command_line->GetSwitchValueASCII(switch_value); 53 } else { 54 *output_value = default_value; 55 } 56 } 57 58 GURL GetURLSwitchValueWithDefault(const char* switch_value, 59 const char* default_value) { 60 std::string string_value; 61 GetSwitchValueWithDefault(switch_value, default_value, &string_value); 62 const GURL result(string_value); 63 DCHECK(result.is_valid()); 64 return result; 65 } 66 67 68 } // namespace 69 70 GaiaUrls* GaiaUrls::GetInstance() { 71 return Singleton<GaiaUrls>::get(); 72 } 73 74 GaiaUrls::GaiaUrls() { 75 gaia_url_ = GetURLSwitchValueWithDefault(switches::kGaiaUrl, kDefaultGaiaUrl); 76 lso_origin_url_ = 77 GetURLSwitchValueWithDefault(switches::kLsoUrl, kDefaultGaiaUrl); 78 google_apis_origin_url_ = GetURLSwitchValueWithDefault( 79 switches::kGoogleApisUrl, kDefaultGoogleApisBaseUrl); 80 81 captcha_base_url_ = 82 GURL("http://" + gaia_url_.host() + 83 (gaia_url_.has_port() ? ":" + gaia_url_.port() : "")); 84 85 oauth2_chrome_client_id_ = 86 google_apis::GetOAuth2ClientID(google_apis::CLIENT_MAIN); 87 oauth2_chrome_client_secret_ = 88 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_MAIN); 89 90 // URLs from accounts.google.com. 91 client_login_url_ = gaia_url_.Resolve(kClientLoginUrlSuffix); 92 service_login_url_ = gaia_url_.Resolve(kServiceLoginUrlSuffix); 93 service_login_auth_url_ = gaia_url_.Resolve(kServiceLoginAuthUrlSuffix); 94 service_logout_url_ = gaia_url_.Resolve(kServiceLogoutUrlSuffix); 95 issue_auth_token_url_ = gaia_url_.Resolve(kIssueAuthTokenUrlSuffix); 96 get_user_info_url_ = gaia_url_.Resolve(kGetUserInfoUrlSuffix); 97 token_auth_url_ = gaia_url_.Resolve(kTokenAuthUrlSuffix); 98 merge_session_url_ = gaia_url_.Resolve(kMergeSessionUrlSuffix); 99 oauth_get_access_token_url_ = 100 gaia_url_.Resolve(kOAuthGetAccessTokenUrlSuffix); 101 oauth_wrap_bridge_url_ = gaia_url_.Resolve(kOAuthWrapBridgeUrlSuffix); 102 oauth_revoke_token_url_ = gaia_url_.Resolve(kOAuthRevokeTokenUrlSuffix); 103 oauth1_login_url_ = gaia_url_.Resolve(kOAuth1LoginUrlSuffix); 104 list_accounts_url_ = gaia_url_.Resolve(kListAccountsSuffix); 105 embedded_signin_url_ = gaia_url_.Resolve(kEmbeddedSigninSuffix); 106 add_account_url_ = gaia_url_.Resolve(kAddAccountSuffix); 107 108 // URLs from accounts.google.com (LSO). 109 get_oauth_token_url_ = lso_origin_url_.Resolve(kGetOAuthTokenUrlSuffix); 110 client_login_to_oauth2_url_ = 111 lso_origin_url_.Resolve(kClientLoginToOAuth2UrlSuffix); 112 oauth2_auth_url_ = lso_origin_url_.Resolve(kOAuth2AuthUrlSuffix); 113 oauth2_token_url_ = lso_origin_url_.Resolve(kOAuth2TokenUrlSuffix); 114 oauth2_revoke_url_ = lso_origin_url_.Resolve(kOAuth2RevokeUrlSuffix); 115 116 // URLs from www.googleapis.com. 117 oauth2_issue_token_url_ = 118 google_apis_origin_url_.Resolve(kOAuth2IssueTokenUrlSuffix); 119 oauth2_token_info_url_ = 120 google_apis_origin_url_.Resolve(kOAuth2TokenInfoUrlSuffix); 121 oauth_user_info_url_ = 122 google_apis_origin_url_.Resolve(kOAuthUserInfoUrlSuffix); 123 124 gaia_login_form_realm_ = gaia_url_; 125 } 126 127 GaiaUrls::~GaiaUrls() { 128 } 129 130 const GURL& GaiaUrls::gaia_url() const { 131 return gaia_url_; 132 } 133 134 const GURL& GaiaUrls::captcha_base_url() const { 135 return captcha_base_url_; 136 } 137 138 const GURL& GaiaUrls::client_login_url() const { 139 return client_login_url_; 140 } 141 142 const GURL& GaiaUrls::service_login_url() const { 143 return service_login_url_; 144 } 145 146 const GURL& GaiaUrls::service_login_auth_url() const { 147 return service_login_auth_url_; 148 } 149 150 const GURL& GaiaUrls::service_logout_url() const { 151 return service_logout_url_; 152 } 153 154 const GURL& GaiaUrls::issue_auth_token_url() const { 155 return issue_auth_token_url_; 156 } 157 158 const GURL& GaiaUrls::get_user_info_url() const { 159 return get_user_info_url_; 160 } 161 162 const GURL& GaiaUrls::token_auth_url() const { 163 return token_auth_url_; 164 } 165 166 const GURL& GaiaUrls::merge_session_url() const { 167 return merge_session_url_; 168 } 169 170 const GURL& GaiaUrls::get_oauth_token_url() const { 171 return get_oauth_token_url_; 172 } 173 174 const GURL& GaiaUrls::oauth_get_access_token_url() const { 175 return oauth_get_access_token_url_; 176 } 177 178 const GURL& GaiaUrls::oauth_wrap_bridge_url() const { 179 return oauth_wrap_bridge_url_; 180 } 181 182 const GURL& GaiaUrls::oauth_user_info_url() const { 183 return oauth_user_info_url_; 184 } 185 186 const GURL& GaiaUrls::oauth_revoke_token_url() const { 187 return oauth_revoke_token_url_; 188 } 189 190 const GURL& GaiaUrls::oauth1_login_url() const { 191 return oauth1_login_url_; 192 } 193 194 const GURL& GaiaUrls::list_accounts_url() const { 195 return list_accounts_url_; 196 } 197 198 const GURL& GaiaUrls::embedded_signin_url() const { 199 return embedded_signin_url_; 200 } 201 202 const GURL& GaiaUrls::add_account_url() const { 203 return add_account_url_; 204 } 205 206 const std::string& GaiaUrls::oauth2_chrome_client_id() const { 207 return oauth2_chrome_client_id_; 208 } 209 210 const std::string& GaiaUrls::oauth2_chrome_client_secret() const { 211 return oauth2_chrome_client_secret_; 212 } 213 214 const GURL& GaiaUrls::client_login_to_oauth2_url() const { 215 return client_login_to_oauth2_url_; 216 } 217 218 const GURL& GaiaUrls::oauth2_auth_url() const { 219 return oauth2_auth_url_; 220 } 221 222 const GURL& GaiaUrls::oauth2_token_url() const { 223 return oauth2_token_url_; 224 } 225 226 const GURL& GaiaUrls::oauth2_issue_token_url() const { 227 return oauth2_issue_token_url_; 228 } 229 230 const GURL& GaiaUrls::oauth2_token_info_url() const { 231 return oauth2_token_info_url_; 232 } 233 234 const GURL& GaiaUrls::oauth2_revoke_url() const { 235 return oauth2_revoke_url_; 236 } 237 238 const GURL& GaiaUrls::gaia_login_form_realm() const { 239 return gaia_url_; 240 } 241