| 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/host/setup/oauth_helper.h" |
| 6 | 6 |
| 7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "google_apis/google_api_keys.h" | 8 #include "google_apis/google_api_keys.h" |
| 9 #include "googleurl/src/url_parse.h" | 9 #include "googleurl/src/url_parse.h" |
| 10 #include "net/base/escape.h" | 10 #include "net/base/escape.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 namespace remoting { | 24 namespace remoting { |
| 25 | 25 |
| 26 std::string GetOauthScope() { | 26 std::string GetOauthScope() { |
| 27 return | 27 return |
| 28 "https://www.googleapis.com/auth/chromoting " | 28 "https://www.googleapis.com/auth/chromoting " |
| 29 "https://www.googleapis.com/auth/googletalk " | 29 "https://www.googleapis.com/auth/googletalk " |
| 30 "https://www.googleapis.com/auth/userinfo.email "; | 30 "https://www.googleapis.com/auth/userinfo.email "; |
| 31 } | 31 } |
| 32 | 32 |
| 33 std::string GetOauthStartUrl() { | 33 std::string GetDefaultOauthRedirectUrl() { |
| 34 return base::StringPrintf( | 34 return |
| 35 "https://accounts.google.com/o/oauth2/auth" | 35 "https://chromoting-oauth.talkgadget.google.com/talkgadget/oauth/" |
| 36 "?scope=%s" | 36 "chrome-remote-desktop/rel/kgngmbheleoaphbjbaiobfdepmghbfah"; |
| 37 "&redirect_uri=%s" | |
| 38 "&response_type=code" | |
| 39 "&client_id=%s" | |
| 40 "&access_type=offline" | |
| 41 "&approval_prompt=force", | |
| 42 net::EscapeUrlEncodedData(GetOauthScope(), true).c_str(), | |
| 43 net::EscapeUrlEncodedData(GetOauthRedirectUrl(), true).c_str(), | |
| 44 net::EscapeUrlEncodedData(google_apis::GetOAuth2ClientID( | |
| 45 google_apis::CLIENT_REMOTING), true).c_str()); | |
| 46 } | 37 } |
| 47 | 38 |
| 48 std::string GetOauthRedirectUrl() { | 39 std::string GetOauthStartUrl(const std::string& redirect_url) { |
| 49 return | 40 return base::StringPrintf( |
| 50 "https://chromoting-oauth.talkgadget.google.com/talkgadget/oauth/" | 41 "https://accounts.google.com/o/oauth2/auth" |
| 51 "chrome-remote-desktop/rel/kgngmbheleoaphbjbaiobfdepmghbfah"; | 42 "?scope=%s" |
| 43 "&redirect_uri=%s" |
| 44 "&response_type=code" |
| 45 "&client_id=%s" |
| 46 "&access_type=offline" |
| 47 "&approval_prompt=force", |
| 48 net::EscapeUrlEncodedData(GetOauthScope(), true).c_str(), |
| 49 redirect_url.c_str(), |
| 50 net::EscapeUrlEncodedData(google_apis::GetOAuth2ClientID( |
| 51 google_apis::CLIENT_REMOTING), true).c_str()); |
| 52 } | 52 } |
| 53 | 53 |
| 54 std::string GetOauthCodeInUrl(const std::string& url) { | 54 std::string GetOauthCodeInUrl(const std::string& url, |
| 55 const std::string& redirect_url) { |
| 55 url_parse::Parsed url_parsed; | 56 url_parse::Parsed url_parsed; |
| 56 ParseStandardURL(url.c_str(), url.length(), &url_parsed); | 57 ParseStandardURL(url.c_str(), url.length(), &url_parsed); |
| 57 std::string redirect = GetOauthRedirectUrl(); | 58 url_parse::Parsed redirect_url_parsed; |
| 58 url_parse::Parsed redirect_parsed; | 59 ParseStandardURL(redirect_url.c_str(), redirect_url.length(), |
| 59 ParseStandardURL(redirect.c_str(), redirect.length(), &redirect_parsed); | 60 &redirect_url_parsed); |
| 60 if (GetComponent(url, url_parsed.scheme) != | 61 if (GetComponent(url, url_parsed.scheme) != |
| 61 GetComponent(redirect, redirect_parsed.scheme)) { | 62 GetComponent(redirect_url, redirect_url_parsed.scheme)) { |
| 62 return ""; | 63 return ""; |
| 63 } | 64 } |
| 64 if (GetComponent(url, url_parsed.host) != | 65 if (GetComponent(url, url_parsed.host) != |
| 65 GetComponent(redirect, redirect_parsed.host)) { | 66 GetComponent(redirect_url, redirect_url_parsed.host)) { |
| 66 return ""; | 67 return ""; |
| 67 } | 68 } |
| 68 url_parse::Component query = url_parsed.query; | 69 url_parse::Component query = url_parsed.query; |
| 69 url_parse::Component key; | 70 url_parse::Component key; |
| 70 url_parse::Component value; | 71 url_parse::Component value; |
| 71 while (ExtractQueryKeyValue(url.c_str(), &query, &key, &value)) { | 72 while (ExtractQueryKeyValue(url.c_str(), &query, &key, &value)) { |
| 72 if (GetComponent(url, key) == "code") { | 73 if (GetComponent(url, key) == "code") { |
| 73 return GetComponent(url, value); | 74 return GetComponent(url, value); |
| 74 } | 75 } |
| 75 } | 76 } |
| 76 return ""; | 77 return ""; |
| 77 } | 78 } |
| 78 | 79 |
| 79 } // namespace remoting | 80 } // namespace remoting |
| OLD | NEW |