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 "google_apis/gaia/gaia_switches.h"
10 #include "google_apis/google_api_keys.h"
14 // Gaia service constants
15 const char kDefaultGaiaUrl[] = "https://accounts.google.com";
16 const char kDefaultGoogleApisBaseUrl[] = "https://www.googleapis.com";
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";
32 const char kEmbeddedSigninSuffix[] = "EmbeddedSignIn";
33 const char kAddAccountSuffix[] = "AddSession";
36 const char kOAuth1LoginScope[] = "https://www.google.com/accounts/OAuthLogin";
37 const char kOAuthWrapBridgeUserInfoScope[] =
38 "https://www.googleapis.com/auth/userinfo.email";
40 // API calls from accounts.google.com (LSO)
41 const char kGetOAuthTokenUrlSuffix[] = "o/oauth/GetOAuthToken/";
42 const char kClientLoginToOAuth2UrlSuffix[] = "o/oauth2/programmatic_auth";
43 const char kOAuth2AuthUrlSuffix[] = "o/oauth2/auth";
44 const char kOAuth2RevokeUrlSuffix[] = "o/oauth2/revoke";
45 const char kOAuth2TokenUrlSuffix[] = "o/oauth2/token";
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 CommandLine* command_line = 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 gaia_url_ = GetURLSwitchValueWithDefault(switches::kGaiaUrl, kDefaultGaiaUrl);
82 GetURLSwitchValueWithDefault(switches::kLsoUrl, kDefaultGaiaUrl);
83 google_apis_origin_url_ = GetURLSwitchValueWithDefault(
84 switches::kGoogleApisUrl, kDefaultGoogleApisBaseUrl);
87 GURL("http://" + gaia_url_.host() +
88 (gaia_url_.has_port() ? ":" + gaia_url_.port() : ""));
90 oauth2_chrome_client_id_ =
91 google_apis::GetOAuth2ClientID(google_apis::CLIENT_MAIN);
92 oauth2_chrome_client_secret_ =
93 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_MAIN);
95 // URLs from accounts.google.com.
96 client_login_url_ = gaia_url_.Resolve(kClientLoginUrlSuffix);
97 service_login_url_ = gaia_url_.Resolve(kServiceLoginUrlSuffix);
98 service_login_auth_url_ = gaia_url_.Resolve(kServiceLoginAuthUrlSuffix);
99 service_logout_url_ = gaia_url_.Resolve(kServiceLogoutUrlSuffix);
100 issue_auth_token_url_ = gaia_url_.Resolve(kIssueAuthTokenUrlSuffix);
101 get_user_info_url_ = gaia_url_.Resolve(kGetUserInfoUrlSuffix);
102 token_auth_url_ = gaia_url_.Resolve(kTokenAuthUrlSuffix);
103 merge_session_url_ = gaia_url_.Resolve(kMergeSessionUrlSuffix);
104 oauth_get_access_token_url_ =
105 gaia_url_.Resolve(kOAuthGetAccessTokenUrlSuffix);
106 oauth_wrap_bridge_url_ = gaia_url_.Resolve(kOAuthWrapBridgeUrlSuffix);
107 oauth_revoke_token_url_ = gaia_url_.Resolve(kOAuthRevokeTokenUrlSuffix);
108 oauth1_login_url_ = gaia_url_.Resolve(kOAuth1LoginUrlSuffix);
109 list_accounts_url_ = gaia_url_.Resolve(kListAccountsSuffix);
110 embedded_signin_url_ = gaia_url_.Resolve(kEmbeddedSigninSuffix);
111 add_account_url_ = gaia_url_.Resolve(kAddAccountSuffix);
113 // URLs from accounts.google.com (LSO).
114 get_oauth_token_url_ = lso_origin_url_.Resolve(kGetOAuthTokenUrlSuffix);
115 client_login_to_oauth2_url_ =
116 lso_origin_url_.Resolve(kClientLoginToOAuth2UrlSuffix);
117 oauth2_auth_url_ = lso_origin_url_.Resolve(kOAuth2AuthUrlSuffix);
118 oauth2_token_url_ = lso_origin_url_.Resolve(kOAuth2TokenUrlSuffix);
119 oauth2_revoke_url_ = lso_origin_url_.Resolve(kOAuth2RevokeUrlSuffix);
121 // URLs from www.googleapis.com.
122 oauth2_issue_token_url_ =
123 google_apis_origin_url_.Resolve(kOAuth2IssueTokenUrlSuffix);
124 oauth2_token_info_url_ =
125 google_apis_origin_url_.Resolve(kOAuth2TokenInfoUrlSuffix);
126 oauth_user_info_url_ =
127 google_apis_origin_url_.Resolve(kOAuthUserInfoUrlSuffix);
129 gaia_login_form_realm_ = gaia_url_;
132 GetSwitchValueWithDefault(switches::kOAuthWrapBridgeUserInfoScope,
133 kOAuthWrapBridgeUserInfoScope,
134 &oauth_wrap_bridge_user_info_scope_);
135 GetSwitchValueWithDefault(switches::kOAuth1LoginScope,
137 &oauth1_login_scope_);
140 GaiaUrls::~GaiaUrls() {
143 const GURL& GaiaUrls::gaia_url() const {
147 const GURL& GaiaUrls::captcha_base_url() const {
148 return captcha_base_url_;
151 const GURL& GaiaUrls::client_login_url() const {
152 return client_login_url_;
155 const GURL& GaiaUrls::service_login_url() const {
156 return service_login_url_;
159 const GURL& GaiaUrls::service_login_auth_url() const {
160 return service_login_auth_url_;
163 const GURL& GaiaUrls::service_logout_url() const {
164 return service_logout_url_;
167 const GURL& GaiaUrls::issue_auth_token_url() const {
168 return issue_auth_token_url_;
171 const GURL& GaiaUrls::get_user_info_url() const {
172 return get_user_info_url_;
175 const GURL& GaiaUrls::token_auth_url() const {
176 return token_auth_url_;
179 const GURL& GaiaUrls::merge_session_url() const {
180 return merge_session_url_;
183 const GURL& GaiaUrls::get_oauth_token_url() const {
184 return get_oauth_token_url_;
187 const GURL& GaiaUrls::oauth_get_access_token_url() const {
188 return oauth_get_access_token_url_;
191 const GURL& GaiaUrls::oauth_wrap_bridge_url() const {
192 return oauth_wrap_bridge_url_;
195 const GURL& GaiaUrls::oauth_user_info_url() const {
196 return oauth_user_info_url_;
199 const GURL& GaiaUrls::oauth_revoke_token_url() const {
200 return oauth_revoke_token_url_;
203 const GURL& GaiaUrls::oauth1_login_url() const {
204 return oauth1_login_url_;
207 const GURL& GaiaUrls::list_accounts_url() const {
208 return list_accounts_url_;
211 const GURL& GaiaUrls::embedded_signin_url() const {
212 return embedded_signin_url_;
215 const GURL& GaiaUrls::add_account_url() const {
216 return add_account_url_;
219 const std::string& GaiaUrls::oauth1_login_scope() const {
220 return oauth1_login_scope_;
223 const std::string& GaiaUrls::oauth_wrap_bridge_user_info_scope() const {
224 return oauth_wrap_bridge_user_info_scope_;
227 const std::string& GaiaUrls::oauth2_chrome_client_id() const {
228 return oauth2_chrome_client_id_;
231 const std::string& GaiaUrls::oauth2_chrome_client_secret() const {
232 return oauth2_chrome_client_secret_;
235 const GURL& GaiaUrls::client_login_to_oauth2_url() const {
236 return client_login_to_oauth2_url_;
239 const GURL& GaiaUrls::oauth2_auth_url() const {
240 return oauth2_auth_url_;
243 const GURL& GaiaUrls::oauth2_token_url() const {
244 return oauth2_token_url_;
247 const GURL& GaiaUrls::oauth2_issue_token_url() const {
248 return oauth2_issue_token_url_;
251 const GURL& GaiaUrls::oauth2_token_info_url() const {
252 return oauth2_token_info_url_;
255 const GURL& GaiaUrls::oauth2_revoke_url() const {
256 return oauth2_revoke_url_;
259 const GURL& GaiaUrls::gaia_login_form_realm() const {