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.
5 #include "google_apis/gaia/gaia_urls.h"
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "base/strings/stringprintf.h"
10 #include "google_apis/gaia/gaia_switches.h"
11 #include "google_apis/google_api_keys.h"
15 // Gaia service constants
16 const char kDefaultGoogleUrl
[] = "http://.google.com";
17 const char kDefaultGaiaUrl
[] = "https://accounts.google.com";
18 const char kDefaultGoogleApisBaseUrl
[] = "https://www.googleapis.com";
20 // API calls from accounts.google.com
21 const char kClientLoginUrlSuffix
[] = "ClientLogin";
22 const char kServiceLoginUrlSuffix
[] = "ServiceLogin";
23 const char kEmbeddedSetupChromeOsUrlSuffix
[] = "embedded/setup/chromeos";
24 const char kServiceLoginAuthUrlSuffix
[] = "ServiceLoginAuth";
25 const char kServiceLogoutUrlSuffix
[] = "Logout";
26 const char kIssueAuthTokenUrlSuffix
[] = "IssueAuthToken";
27 const char kGetUserInfoUrlSuffix
[] = "GetUserInfo";
28 const char kTokenAuthUrlSuffix
[] = "TokenAuth";
29 const char kMergeSessionUrlSuffix
[] = "MergeSession";
30 const char kOAuthGetAccessTokenUrlSuffix
[] = "OAuthGetAccessToken";
31 const char kOAuthWrapBridgeUrlSuffix
[] = "OAuthWrapBridge";
32 const char kOAuth1LoginUrlSuffix
[] = "OAuthLogin";
33 const char kOAuthRevokeTokenUrlSuffix
[] = "AuthSubRevokeToken";
34 const char kListAccountsSuffix
[] = "ListAccounts?json=standard";
35 const char kEmbeddedSigninSuffix
[] = "EmbeddedSignIn";
36 const char kAddAccountSuffix
[] = "AddSession";
37 const char kGetCheckConnectionInfoSuffix
[] = "GetCheckConnectionInfo";
39 // API calls from accounts.google.com (LSO)
40 const char kGetOAuthTokenUrlSuffix
[] = "o/oauth/GetOAuthToken/";
41 const char kClientLoginToOAuth2UrlSuffix
[] = "o/oauth2/programmatic_auth";
42 const char kOAuth2AuthUrlSuffix
[] = "o/oauth2/auth";
43 const char kOAuth2RevokeUrlSuffix
[] = "o/oauth2/revoke";
44 const char kOAuth2TokenUrlSuffix
[] = "o/oauth2/token";
45 const char kOAuth2IFrameUrlSuffix
[] = "o/oauth2/iframerpc";
47 // API calls from www.googleapis.com
48 const char kOAuth2IssueTokenUrlSuffix
[] = "oauth2/v2/IssueToken";
49 const char kOAuth2TokenInfoUrlSuffix
[] = "oauth2/v2/tokeninfo";
50 const char kOAuthUserInfoUrlSuffix
[] = "oauth2/v1/userinfo";
52 void GetSwitchValueWithDefault(const char* switch_value
,
53 const char* default_value
,
54 std::string
* output_value
) {
55 base::CommandLine
* command_line
= base::CommandLine::ForCurrentProcess();
56 if (command_line
->HasSwitch(switch_value
)) {
57 *output_value
= command_line
->GetSwitchValueASCII(switch_value
);
59 *output_value
= default_value
;
63 GURL
GetURLSwitchValueWithDefault(const char* switch_value
,
64 const char* default_value
) {
65 std::string string_value
;
66 GetSwitchValueWithDefault(switch_value
, default_value
, &string_value
);
67 const GURL
result(string_value
);
68 DCHECK(result
.is_valid());
75 GaiaUrls
* GaiaUrls::GetInstance() {
76 return Singleton
<GaiaUrls
>::get();
79 GaiaUrls::GaiaUrls() {
80 google_url_
= GetURLSwitchValueWithDefault(switches::kGoogleUrl
,
82 gaia_url_
= GetURLSwitchValueWithDefault(switches::kGaiaUrl
, kDefaultGaiaUrl
);
84 GetURLSwitchValueWithDefault(switches::kLsoUrl
, kDefaultGaiaUrl
);
85 google_apis_origin_url_
= GetURLSwitchValueWithDefault(
86 switches::kGoogleApisUrl
, kDefaultGoogleApisBaseUrl
);
89 GURL("http://" + gaia_url_
.host() +
90 (gaia_url_
.has_port() ? ":" + gaia_url_
.port() : ""));
92 oauth2_chrome_client_id_
=
93 google_apis::GetOAuth2ClientID(google_apis::CLIENT_MAIN
);
94 oauth2_chrome_client_secret_
=
95 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_MAIN
);
97 // URLs from accounts.google.com.
98 client_login_url_
= gaia_url_
.Resolve(kClientLoginUrlSuffix
);
99 service_login_url_
= gaia_url_
.Resolve(kServiceLoginUrlSuffix
);
100 embedded_setup_chromeos_url_
=
101 gaia_url_
.Resolve(kEmbeddedSetupChromeOsUrlSuffix
);
102 service_login_auth_url_
= gaia_url_
.Resolve(kServiceLoginAuthUrlSuffix
);
103 service_logout_url_
= gaia_url_
.Resolve(kServiceLogoutUrlSuffix
);
104 issue_auth_token_url_
= gaia_url_
.Resolve(kIssueAuthTokenUrlSuffix
);
105 get_user_info_url_
= gaia_url_
.Resolve(kGetUserInfoUrlSuffix
);
106 token_auth_url_
= gaia_url_
.Resolve(kTokenAuthUrlSuffix
);
107 merge_session_url_
= gaia_url_
.Resolve(kMergeSessionUrlSuffix
);
108 oauth_get_access_token_url_
=
109 gaia_url_
.Resolve(kOAuthGetAccessTokenUrlSuffix
);
110 oauth_wrap_bridge_url_
= gaia_url_
.Resolve(kOAuthWrapBridgeUrlSuffix
);
111 oauth_revoke_token_url_
= gaia_url_
.Resolve(kOAuthRevokeTokenUrlSuffix
);
112 oauth1_login_url_
= gaia_url_
.Resolve(kOAuth1LoginUrlSuffix
);
113 list_accounts_url_
= gaia_url_
.Resolve(kListAccountsSuffix
);
114 embedded_signin_url_
= gaia_url_
.Resolve(kEmbeddedSigninSuffix
);
115 add_account_url_
= gaia_url_
.Resolve(kAddAccountSuffix
);
116 get_check_connection_info_url_
=
117 gaia_url_
.Resolve(kGetCheckConnectionInfoSuffix
);
119 // URLs from accounts.google.com (LSO).
120 get_oauth_token_url_
= lso_origin_url_
.Resolve(kGetOAuthTokenUrlSuffix
);
121 client_login_to_oauth2_url_
=
122 lso_origin_url_
.Resolve(kClientLoginToOAuth2UrlSuffix
);
123 oauth2_auth_url_
= lso_origin_url_
.Resolve(kOAuth2AuthUrlSuffix
);
124 oauth2_token_url_
= lso_origin_url_
.Resolve(kOAuth2TokenUrlSuffix
);
125 oauth2_revoke_url_
= lso_origin_url_
.Resolve(kOAuth2RevokeUrlSuffix
);
127 lso_origin_url_
.Resolve(kOAuth2IFrameUrlSuffix
);
129 // URLs from www.googleapis.com.
130 oauth2_issue_token_url_
=
131 google_apis_origin_url_
.Resolve(kOAuth2IssueTokenUrlSuffix
);
132 oauth2_token_info_url_
=
133 google_apis_origin_url_
.Resolve(kOAuth2TokenInfoUrlSuffix
);
134 oauth_user_info_url_
=
135 google_apis_origin_url_
.Resolve(kOAuthUserInfoUrlSuffix
);
137 gaia_login_form_realm_
= gaia_url_
;
140 GaiaUrls::~GaiaUrls() {
143 const GURL
& GaiaUrls::google_url() const {
147 const GURL
& GaiaUrls::gaia_url() const {
151 const GURL
& GaiaUrls::captcha_base_url() const {
152 return captcha_base_url_
;
155 const GURL
& GaiaUrls::client_login_url() const {
156 return client_login_url_
;
159 const GURL
& GaiaUrls::service_login_url() const {
160 return service_login_url_
;
163 const GURL
& GaiaUrls::embedded_setup_chromeos_url() const {
164 return embedded_setup_chromeos_url_
;
168 const GURL
& GaiaUrls::service_login_auth_url() const {
169 return service_login_auth_url_
;
172 const GURL
& GaiaUrls::service_logout_url() const {
173 return service_logout_url_
;
176 const GURL
& GaiaUrls::issue_auth_token_url() const {
177 return issue_auth_token_url_
;
180 const GURL
& GaiaUrls::get_user_info_url() const {
181 return get_user_info_url_
;
184 const GURL
& GaiaUrls::token_auth_url() const {
185 return token_auth_url_
;
188 const GURL
& GaiaUrls::merge_session_url() const {
189 return merge_session_url_
;
192 const GURL
& GaiaUrls::get_oauth_token_url() const {
193 return get_oauth_token_url_
;
196 const GURL
& GaiaUrls::oauth_get_access_token_url() const {
197 return oauth_get_access_token_url_
;
200 const GURL
& GaiaUrls::oauth_wrap_bridge_url() const {
201 return oauth_wrap_bridge_url_
;
204 const GURL
& GaiaUrls::oauth_user_info_url() const {
205 return oauth_user_info_url_
;
208 const GURL
& GaiaUrls::oauth_revoke_token_url() const {
209 return oauth_revoke_token_url_
;
212 const GURL
& GaiaUrls::oauth2_iframe_url() const {
213 return oauth2_iframe_url_
;
216 const GURL
& GaiaUrls::oauth1_login_url() const {
217 return oauth1_login_url_
;
220 const GURL
& GaiaUrls::embedded_signin_url() const {
221 return embedded_signin_url_
;
224 const GURL
& GaiaUrls::add_account_url() const {
225 return add_account_url_
;
228 const std::string
& GaiaUrls::oauth2_chrome_client_id() const {
229 return oauth2_chrome_client_id_
;
232 const std::string
& GaiaUrls::oauth2_chrome_client_secret() const {
233 return oauth2_chrome_client_secret_
;
236 const GURL
& GaiaUrls::client_login_to_oauth2_url() const {
237 return client_login_to_oauth2_url_
;
240 const GURL
& GaiaUrls::oauth2_auth_url() const {
241 return oauth2_auth_url_
;
244 const GURL
& GaiaUrls::oauth2_token_url() const {
245 return oauth2_token_url_
;
248 const GURL
& GaiaUrls::oauth2_issue_token_url() const {
249 return oauth2_issue_token_url_
;
252 const GURL
& GaiaUrls::oauth2_token_info_url() const {
253 return oauth2_token_info_url_
;
256 const GURL
& GaiaUrls::oauth2_revoke_url() const {
257 return oauth2_revoke_url_
;
260 const GURL
& GaiaUrls::gaia_login_form_realm() const {
264 GURL
GaiaUrls::ListAccountsURLWithSource(const std::string
& source
) {
265 if (source
.empty()) {
266 return list_accounts_url_
;
268 std::string query
= list_accounts_url_
.query();
269 return list_accounts_url_
.Resolve(
270 base::StringPrintf("?source=%s&%s", source
.c_str(), query
.c_str()));
274 GURL
GaiaUrls::GetCheckConnectionInfoURLWithSource(const std::string
& source
) {
275 return source
.empty()
276 ? get_check_connection_info_url_
277 : get_check_connection_info_url_
.Resolve(
278 base::StringPrintf("?source=%s", source
.c_str()));