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