OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/setup/oauth_helper.h" | 5 #include "remoting/base/oauth_helper.h" |
6 | 6 |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "google_apis/google_api_keys.h" | 8 #include "google_apis/google_api_keys.h" |
9 #include "net/base/escape.h" | 9 #include "net/base/escape.h" |
10 #include "url/third_party/mozilla/url_parse.h" | 10 #include "url/third_party/mozilla/url_parse.h" |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 std::string GetComponent(const std::string& url, | 14 std::string GetComponent(const std::string& url, |
15 const url::Component component) { | 15 const url::Component component) { |
16 if (component.len < 0) { | 16 if (component.len < 0) { |
17 return std::string(); | 17 return std::string(); |
18 } | 18 } |
19 return url.substr(component.begin, component.len); | 19 return url.substr(component.begin, component.len); |
20 } | 20 } |
21 | 21 |
22 } // namespace | 22 } // namespace |
23 | 23 |
24 namespace remoting { | 24 namespace remoting { |
25 | 25 |
26 std::string GetOauthScope() { | 26 std::string GetOauthScope() { |
27 return | 27 return "https://www.googleapis.com/auth/chromoting " |
28 "https://www.googleapis.com/auth/chromoting " | 28 "https://www.googleapis.com/auth/googletalk " |
29 "https://www.googleapis.com/auth/googletalk " | 29 "https://www.googleapis.com/auth/userinfo.email "; |
30 "https://www.googleapis.com/auth/userinfo.email "; | |
31 } | 30 } |
32 | 31 |
33 std::string GetDefaultOauthRedirectUrl() { | 32 std::string GetDefaultOauthRedirectUrl() { |
34 return | 33 return "https://chromoting-oauth.talkgadget.google.com/talkgadget/oauth/" |
35 "https://chromoting-oauth.talkgadget.google.com/talkgadget/oauth/" | 34 "chrome-remote-desktop/rel/kgngmbheleoaphbjbaiobfdepmghbfah"; |
36 "chrome-remote-desktop/rel/kgngmbheleoaphbjbaiobfdepmghbfah"; | |
37 } | 35 } |
38 | 36 |
39 std::string GetOauthStartUrl(const std::string& redirect_url) { | 37 std::string GetOauthStartUrl(const std::string& redirect_url) { |
40 return base::StringPrintf( | 38 return base::StringPrintf( |
41 "https://accounts.google.com/o/oauth2/auth" | 39 "https://accounts.google.com/o/oauth2/auth" |
42 "?scope=%s" | 40 "?scope=%s" |
43 "&redirect_uri=%s" | 41 "&redirect_uri=%s" |
44 "&response_type=code" | 42 "&response_type=code" |
45 "&client_id=%s" | 43 "&client_id=%s" |
46 "&access_type=offline" | 44 "&access_type=offline" |
47 "&approval_prompt=force", | 45 "&approval_prompt=force", |
48 net::EscapeUrlEncodedData(GetOauthScope(), true).c_str(), | 46 net::EscapeUrlEncodedData(GetOauthScope(), true).c_str(), |
49 redirect_url.c_str(), | 47 redirect_url.c_str(), |
50 net::EscapeUrlEncodedData(google_apis::GetOAuth2ClientID( | 48 net::EscapeUrlEncodedData( |
51 google_apis::CLIENT_REMOTING), true).c_str()); | 49 google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING), true) |
| 50 .c_str()); |
52 } | 51 } |
53 | 52 |
54 std::string GetOauthCodeInUrl(const std::string& url, | 53 std::string GetOauthCodeInUrl(const std::string& url, |
55 const std::string& redirect_url) { | 54 const std::string& redirect_url) { |
56 url::Parsed url_parsed; | 55 url::Parsed url_parsed; |
57 ParseStandardURL(url.c_str(), url.length(), &url_parsed); | 56 ParseStandardURL(url.c_str(), url.length(), &url_parsed); |
58 url::Parsed redirect_url_parsed; | 57 url::Parsed redirect_url_parsed; |
59 ParseStandardURL(redirect_url.c_str(), redirect_url.length(), | 58 ParseStandardURL(redirect_url.c_str(), redirect_url.length(), |
60 &redirect_url_parsed); | 59 &redirect_url_parsed); |
61 if (GetComponent(url, url_parsed.scheme) != | 60 if (GetComponent(url, url_parsed.scheme) != |
62 GetComponent(redirect_url, redirect_url_parsed.scheme)) { | 61 GetComponent(redirect_url, redirect_url_parsed.scheme)) { |
63 return std::string(); | 62 return std::string(); |
64 } | 63 } |
65 if (GetComponent(url, url_parsed.host) != | 64 if (GetComponent(url, url_parsed.host) != |
66 GetComponent(redirect_url, redirect_url_parsed.host)) { | 65 GetComponent(redirect_url, redirect_url_parsed.host)) { |
67 return std::string(); | 66 return std::string(); |
68 } | 67 } |
69 url::Component query = url_parsed.query; | 68 url::Component query = url_parsed.query; |
70 url::Component key; | 69 url::Component key; |
71 url::Component value; | 70 url::Component value; |
72 while (ExtractQueryKeyValue(url.c_str(), &query, &key, &value)) { | 71 while (ExtractQueryKeyValue(url.c_str(), &query, &key, &value)) { |
73 if (GetComponent(url, key) == "code") { | 72 if (GetComponent(url, key) == "code") { |
74 return GetComponent(url, value); | 73 return GetComponent(url, value); |
75 } | 74 } |
76 } | 75 } |
77 return std::string(); | 76 return std::string(); |
78 } | 77 } |
79 | 78 |
80 } // namespace remoting | 79 } // namespace remoting |
OLD | NEW |