OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/host/it2me/it2me_native_messaging_host.h" | 5 #include "remoting/host/it2me/it2me_native_messaging_host.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
13 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_util.h" |
15 #include "base/strings/stringize_macros.h" | 16 #include "base/strings/stringize_macros.h" |
16 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
17 #include "base/values.h" | 18 #include "base/values.h" |
18 #include "media/base/media.h" | 19 #include "media/base/media.h" |
19 #include "net/base/net_util.h" | 20 #include "net/base/net_util.h" |
20 #include "net/url_request/url_request_context_getter.h" | 21 #include "net/url_request/url_request_context_getter.h" |
21 #include "remoting/base/auth_token_util.h" | |
22 #include "remoting/base/service_urls.h" | 22 #include "remoting/base/service_urls.h" |
23 #include "remoting/host/chromoting_host_context.h" | 23 #include "remoting/host/chromoting_host_context.h" |
24 #include "remoting/host/host_exit_codes.h" | 24 #include "remoting/host/host_exit_codes.h" |
25 #include "remoting/protocol/name_value_map.h" | 25 #include "remoting/protocol/name_value_map.h" |
26 | 26 |
27 namespace remoting { | 27 namespace remoting { |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
31 const remoting::protocol::NameMapElement<It2MeHostState> kIt2MeHostStates[] = { | 31 const remoting::protocol::NameMapElement<It2MeHostState> kIt2MeHostStates[] = { |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 return; | 157 return; |
158 } | 158 } |
159 | 159 |
160 std::string auth_service_with_token; | 160 std::string auth_service_with_token; |
161 if (!message.GetString("authServiceWithToken", &auth_service_with_token)) { | 161 if (!message.GetString("authServiceWithToken", &auth_service_with_token)) { |
162 SendErrorAndExit(response.Pass(), | 162 SendErrorAndExit(response.Pass(), |
163 "'authServiceWithToken' not found in request."); | 163 "'authServiceWithToken' not found in request."); |
164 return; | 164 return; |
165 } | 165 } |
166 | 166 |
167 ParseAuthTokenWithService(auth_service_with_token, | 167 // For backward compatibility the webapp still passes OAuth service as part of |
168 &xmpp_config.auth_token, | 168 // the authServiceWithToken field. But auth service part is always expected to |
169 &xmpp_config.auth_service); | 169 // be set to oauth2. |
170 if (xmpp_config.auth_token.empty()) { | 170 const char kOAuth2ServicePrefix[] = "oauth2:"; |
171 SendErrorAndExit( | 171 if (!StartsWithASCII(auth_service_with_token, kOAuth2ServicePrefix, true)) { |
172 response.Pass(), | 172 SendErrorAndExit(response.Pass(), "Invalid 'authServiceWithToken': " + |
173 "Invalid 'authServiceWithToken': " + auth_service_with_token); | 173 auth_service_with_token); |
174 return; | 174 return; |
175 } | 175 } |
176 | 176 |
| 177 xmpp_config.auth_token = |
| 178 auth_service_with_token.substr(strlen(kOAuth2ServicePrefix)); |
| 179 |
177 #if !defined(NDEBUG) | 180 #if !defined(NDEBUG) |
178 std::string address; | 181 std::string address; |
179 if (!message.GetString("xmppServerAddress", &address)) { | 182 if (!message.GetString("xmppServerAddress", &address)) { |
180 SendErrorAndExit(response.Pass(), | 183 SendErrorAndExit(response.Pass(), |
181 "'xmppServerAddress' not found in request."); | 184 "'xmppServerAddress' not found in request."); |
182 return; | 185 return; |
183 } | 186 } |
184 | 187 |
185 if (!net::ParseHostAndPort( | 188 if (!net::ParseHostAndPort( |
186 address, &xmpp_server_config_.host, &xmpp_server_config_.port)) { | 189 address, &xmpp_server_config_.host, &xmpp_server_config_.port)) { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 } | 309 } |
307 | 310 |
308 /* static */ | 311 /* static */ |
309 std::string It2MeNativeMessagingHost::HostStateToString( | 312 std::string It2MeNativeMessagingHost::HostStateToString( |
310 It2MeHostState host_state) { | 313 It2MeHostState host_state) { |
311 return ValueToName(kIt2MeHostStates, host_state); | 314 return ValueToName(kIt2MeHostStates, host_state); |
312 } | 315 } |
313 | 316 |
314 } // namespace remoting | 317 } // namespace remoting |
315 | 318 |
OLD | NEW |