gaia_urls.cc revision 5821806d5e7f356e8fa4b058a389a808ea183019
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 "google_apis/gaia/gaia_switches.h"
9#include "google_apis/google_api_keys.h"
10
11namespace {
12
13// Gaia service constants
14const char kDefaultGaiaBaseUrl[] = "accounts.google.com";
15const char kCaptchaUrlPrefixSuffix[] = "/";
16const char kClientLoginUrlSuffix[] = "/ClientLogin";
17const char kServiceLoginUrlSuffix[] = "/ServiceLogin";
18const char kIssueAuthTokenUrlSuffix[] = "/IssueAuthToken";
19const char kGetUserInfoUrlSuffix[] = "/GetUserInfo";
20const char kTokenAuthUrlSuffix[] = "/TokenAuth";
21const char kMergeSessionUrlSuffix[] = "/MergeSession";
22
23const char kOAuthGetAccessTokenUrlSuffix[] = "/OAuthGetAccessToken";
24const char kOAuthWrapBridgeUrlSuffix[] = "/OAuthWrapBridge";
25const char kOAuth1LoginUrlSuffix[] = "/OAuthLogin";
26const char kOAuthRevokeTokenUrlSuffix[] = "/AuthSubRevokeToken";
27
28// Federated login constants
29const char kDefaultFederatedLoginHost[] = "www.google.com";
30const char kDefaultFederatedLoginPath[] = "/accounts";
31const char kGetOAuthTokenUrlSuffix[] = "/o/oauth/GetOAuthToken/";
32
33const char kClientLoginToOAuth2Url[] =
34    "https://accounts.google.com/o/oauth2/programmatic_auth";
35const char kOAuth2TokenUrl[] =
36    "https://accounts.google.com/o/oauth2/token";
37const char kOAuth2IssueTokenUrl[] =
38    "https://www.googleapis.com/oauth2/v2/IssueToken";
39const char kOAuth1LoginScope[] =
40    "https://www.google.com/accounts/OAuthLogin";
41
42void GetSwitchValueWithDefault(const char* switch_value,
43                               const char* default_value,
44                               std::string* output_value) {
45  CommandLine* command_line = CommandLine::ForCurrentProcess();
46  if (command_line->HasSwitch(switch_value)) {
47    *output_value = command_line->GetSwitchValueASCII(switch_value);
48  } else {
49    *output_value = default_value;
50  }
51}
52
53}  // namespace
54
55GaiaUrls* GaiaUrls::GetInstance() {
56  return Singleton<GaiaUrls>::get();
57}
58
59GaiaUrls::GaiaUrls() {
60  CommandLine* command_line = CommandLine::ForCurrentProcess();
61  std::string host_base;
62  GetSwitchValueWithDefault(switches::kGaiaHost, kDefaultGaiaBaseUrl,
63                            &host_base);
64
65  captcha_url_prefix_ = "http://" + host_base + kCaptchaUrlPrefixSuffix;
66  gaia_origin_url_ = "https://" + host_base;
67  std::string gaia_url_base = gaia_origin_url_;
68  if (command_line->HasSwitch(switches::kGaiaUrlPath)) {
69    std::string path =
70        command_line->GetSwitchValueASCII(switches::kGaiaUrlPath);
71    if (!path.empty()) {
72      if (path[0] != '/')
73        gaia_url_base.append("/");
74
75      gaia_url_base.append(path);
76    }
77  }
78
79  client_login_url_ = gaia_url_base + kClientLoginUrlSuffix;
80  service_login_url_ = gaia_url_base + kServiceLoginUrlSuffix;
81  issue_auth_token_url_ = gaia_url_base + kIssueAuthTokenUrlSuffix;
82  get_user_info_url_ = gaia_url_base + kGetUserInfoUrlSuffix;
83  token_auth_url_ = gaia_url_base + kTokenAuthUrlSuffix;
84  merge_session_url_ = gaia_url_base + kMergeSessionUrlSuffix;
85  get_oauth_token_url_ = gaia_url_base + kGetOAuthTokenUrlSuffix;
86  oauth_get_access_token_url_ = gaia_url_base +
87                                kOAuthGetAccessTokenUrlSuffix;
88  oauth_wrap_bridge_url_ = gaia_url_base + kOAuthWrapBridgeUrlSuffix;
89  oauth_revoke_token_url_ = gaia_url_base + kOAuthRevokeTokenUrlSuffix;
90  oauth1_login_url_ = gaia_url_base + kOAuth1LoginUrlSuffix;
91
92  GetSwitchValueWithDefault(switches::kOAuth1LoginScope,
93                            kOAuth1LoginScope,
94                            &oauth1_login_scope_);
95
96  // TODO(joaodasilva): these aren't configurable for now, but are managed here
97  // so that users of Gaia URLs don't have to use static constants.
98  // http://crbug.com/97126
99  oauth_user_info_url_ = "https://www.googleapis.com/oauth2/v1/userinfo";
100  oauth_wrap_bridge_user_info_scope_ =
101      "https://www.googleapis.com/auth/userinfo.email";
102  client_oauth_url_ = "https://accounts.google.com/ClientOAuth";
103
104  oauth2_chrome_client_id_ =
105      google_apis::GetOAuth2ClientID(google_apis::CLIENT_MAIN);
106  oauth2_chrome_client_secret_ =
107      google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_MAIN);
108
109  GetSwitchValueWithDefault(switches::kClientLoginToOAuth2Url,
110                            kClientLoginToOAuth2Url,
111                            &client_login_to_oauth2_url_);
112  GetSwitchValueWithDefault(switches::kOAuth2TokenUrl,
113                            kOAuth2TokenUrl,
114                            &oauth2_token_url_);
115  GetSwitchValueWithDefault(switches::kOAuth2IssueTokenUrl,
116                            kOAuth2IssueTokenUrl,
117                            &oauth2_issue_token_url_);
118
119  gaia_login_form_realm_ = "https://accounts.google.com/";
120}
121
122GaiaUrls::~GaiaUrls() {
123}
124
125const std::string& GaiaUrls::captcha_url_prefix() {
126  return captcha_url_prefix_;
127}
128
129const std::string& GaiaUrls::gaia_origin_url() {
130  return gaia_origin_url_;
131}
132
133const std::string& GaiaUrls::client_login_url() {
134  return client_login_url_;
135}
136
137const std::string& GaiaUrls::service_login_url() {
138  return service_login_url_;
139}
140
141const std::string& GaiaUrls::issue_auth_token_url() {
142  return issue_auth_token_url_;
143}
144
145const std::string& GaiaUrls::get_user_info_url() {
146  return get_user_info_url_;
147}
148
149const std::string& GaiaUrls::token_auth_url() {
150  return token_auth_url_;
151}
152
153const std::string& GaiaUrls::merge_session_url() {
154  return merge_session_url_;
155}
156
157const std::string& GaiaUrls::get_oauth_token_url() {
158  return get_oauth_token_url_;
159}
160
161const std::string& GaiaUrls::oauth_get_access_token_url() {
162  return oauth_get_access_token_url_;
163}
164
165const std::string& GaiaUrls::oauth_wrap_bridge_url() {
166  return oauth_wrap_bridge_url_;
167}
168
169const std::string& GaiaUrls::oauth_user_info_url() {
170  return oauth_user_info_url_;
171}
172
173const std::string& GaiaUrls::oauth_revoke_token_url() {
174  return oauth_revoke_token_url_;
175}
176
177const std::string& GaiaUrls::oauth1_login_url() {
178  return oauth1_login_url_;
179}
180
181const std::string& GaiaUrls::oauth1_login_scope() {
182  return oauth1_login_scope_;
183}
184
185const std::string& GaiaUrls::oauth_wrap_bridge_user_info_scope() {
186  return oauth_wrap_bridge_user_info_scope_;
187}
188
189const std::string& GaiaUrls::client_oauth_url() {
190  return client_oauth_url_;
191}
192
193const std::string& GaiaUrls::oauth2_chrome_client_id() {
194  return oauth2_chrome_client_id_;
195}
196
197const std::string& GaiaUrls::oauth2_chrome_client_secret() {
198  return oauth2_chrome_client_secret_;
199}
200
201const std::string& GaiaUrls::client_login_to_oauth2_url() {
202  return client_login_to_oauth2_url_;
203}
204
205const std::string& GaiaUrls::oauth2_token_url() {
206  return oauth2_token_url_;
207}
208
209const std::string& GaiaUrls::oauth2_issue_token_url() {
210  return oauth2_issue_token_url_;
211}
212
213
214const std::string& GaiaUrls::gaia_login_form_realm() {
215  return gaia_login_form_realm_;
216}
217