gaia_urls.cc revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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";
34
35// API calls from accounts.google.com (LSO)
36const char kGetOAuthTokenUrlSuffix[] = "o/oauth/GetOAuthToken/";
37const char kClientLoginToOAuth2UrlSuffix[] = "o/oauth2/programmatic_auth";
38const char kOAuth2AuthUrlSuffix[] = "o/oauth2/auth";
39const char kOAuth2RevokeUrlSuffix[] = "o/oauth2/revoke";
40const char kOAuth2TokenUrlSuffix[] = "o/oauth2/token";
41
42// API calls from www.googleapis.com
43const char kOAuth2IssueTokenUrlSuffix[] = "oauth2/v2/IssueToken";
44const char kOAuth2TokenInfoUrlSuffix[] = "oauth2/v2/tokeninfo";
45const char kOAuthUserInfoUrlSuffix[] = "oauth2/v1/userinfo";
46
47void 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
58GURL 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
70GaiaUrls* GaiaUrls::GetInstance() {
71  return Singleton<GaiaUrls>::get();
72}
73
74GaiaUrls::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
127GaiaUrls::~GaiaUrls() {
128}
129
130const GURL& GaiaUrls::gaia_url() const {
131  return gaia_url_;
132}
133
134const GURL& GaiaUrls::captcha_base_url() const {
135  return captcha_base_url_;
136}
137
138const GURL& GaiaUrls::client_login_url() const {
139  return client_login_url_;
140}
141
142const GURL& GaiaUrls::service_login_url() const {
143  return service_login_url_;
144}
145
146const GURL& GaiaUrls::service_login_auth_url() const {
147  return service_login_auth_url_;
148}
149
150const GURL& GaiaUrls::service_logout_url() const {
151  return service_logout_url_;
152}
153
154const GURL& GaiaUrls::issue_auth_token_url() const {
155  return issue_auth_token_url_;
156}
157
158const GURL& GaiaUrls::get_user_info_url() const {
159  return get_user_info_url_;
160}
161
162const GURL& GaiaUrls::token_auth_url() const {
163  return token_auth_url_;
164}
165
166const GURL& GaiaUrls::merge_session_url() const {
167  return merge_session_url_;
168}
169
170const GURL& GaiaUrls::get_oauth_token_url() const {
171  return get_oauth_token_url_;
172}
173
174const GURL& GaiaUrls::oauth_get_access_token_url() const {
175  return oauth_get_access_token_url_;
176}
177
178const GURL& GaiaUrls::oauth_wrap_bridge_url() const {
179  return oauth_wrap_bridge_url_;
180}
181
182const GURL& GaiaUrls::oauth_user_info_url() const {
183  return oauth_user_info_url_;
184}
185
186const GURL& GaiaUrls::oauth_revoke_token_url() const {
187  return oauth_revoke_token_url_;
188}
189
190const GURL& GaiaUrls::oauth1_login_url() const {
191  return oauth1_login_url_;
192}
193
194const GURL& GaiaUrls::list_accounts_url() const {
195  return list_accounts_url_;
196}
197
198const GURL& GaiaUrls::embedded_signin_url() const {
199  return embedded_signin_url_;
200}
201
202const GURL& GaiaUrls::add_account_url() const {
203  return add_account_url_;
204}
205
206const std::string& GaiaUrls::oauth2_chrome_client_id() const {
207  return oauth2_chrome_client_id_;
208}
209
210const std::string& GaiaUrls::oauth2_chrome_client_secret() const {
211  return oauth2_chrome_client_secret_;
212}
213
214const GURL& GaiaUrls::client_login_to_oauth2_url() const {
215  return client_login_to_oauth2_url_;
216}
217
218const GURL& GaiaUrls::oauth2_auth_url() const {
219  return oauth2_auth_url_;
220}
221
222const GURL& GaiaUrls::oauth2_token_url() const {
223  return oauth2_token_url_;
224}
225
226const GURL& GaiaUrls::oauth2_issue_token_url() const {
227  return oauth2_issue_token_url_;
228}
229
230const GURL& GaiaUrls::oauth2_token_info_url() const {
231  return oauth2_token_info_url_;
232}
233
234const GURL& GaiaUrls::oauth2_revoke_url() const {
235  return oauth2_revoke_url_;
236}
237
238const GURL& GaiaUrls::gaia_login_form_realm() const {
239  return gaia_url_;
240}
241