| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "components/signin/core/browser/dice_header_helper.h" | 5 #include "components/signin/core/browser/dice_header_helper.h" |
| 6 | 6 |
| 7 #include "components/signin/core/common/profile_management_switches.h" | 7 #include "components/signin/core/common/profile_management_switches.h" |
| 8 #include "google_apis/gaia/gaia_auth_util.h" | 8 #include "google_apis/gaia/gaia_auth_util.h" |
| 9 #include "google_apis/gaia/gaia_urls.h" | 9 #include "google_apis/gaia/gaia_urls.h" |
| 10 #include "url/gurl.h" | 10 #include "url/gurl.h" |
| 11 | 11 |
| 12 namespace signin { | 12 namespace signin { |
| 13 | 13 |
| 14 namespace { |
| 15 |
| 16 const char kActionAttrName[] = "action"; |
| 17 const char kAuthUserAttrName[] = "authuser"; |
| 18 const char kAuthorizationCodeAttrName[] = "authorization_code"; |
| 19 const char kEmailAttrName[] = "email"; |
| 20 const char kIdAttrName[] = "id"; |
| 21 const char kLogoutAttrName[] = "logout"; |
| 22 |
| 23 // Determines the Dice action that has been passed from Gaia in the header. |
| 24 DiceAction GetDiceActionFromHeader(const std::string& value) { |
| 25 if (value == "SIGNIN") |
| 26 return DiceAction::SIGNIN; |
| 27 else if (value == "SIGNOUT") |
| 28 return DiceAction::SIGNOUT; |
| 29 else if (value == "SINGLE_SESSION_SIGN_OUT") |
| 30 return DiceAction::SINGLE_SESSION_SIGNOUT; |
| 31 else |
| 32 return DiceAction::NONE; |
| 33 } |
| 34 |
| 35 } // namespace |
| 36 |
| 37 // static |
| 38 DiceResponseParams DiceHeaderHelper::BuildDiceResponseParams( |
| 39 const std::string& header_value) { |
| 40 DCHECK(!header_value.empty()); |
| 41 DiceResponseParams params; |
| 42 ResponseHeaderDictionary header_dictionary = |
| 43 ParseAccountConsistencyResponseHeader(header_value); |
| 44 ResponseHeaderDictionary::const_iterator it = header_dictionary.begin(); |
| 45 for (; it != header_dictionary.end(); ++it) { |
| 46 const std::string key_name(it->first); |
| 47 const std::string value(it->second); |
| 48 if (key_name == kActionAttrName) { |
| 49 params.user_intention = GetDiceActionFromHeader(value); |
| 50 } else if (key_name == kIdAttrName) { |
| 51 params.obfuscated_gaia_id = value; |
| 52 } else if (key_name == kEmailAttrName) { |
| 53 params.email = value; |
| 54 } else if (key_name == kAuthUserAttrName) { |
| 55 params.session_index = value; |
| 56 } else if (key_name == kAuthorizationCodeAttrName) { |
| 57 params.authorization_code = value; |
| 58 } else if (key_name == kLogoutAttrName) { |
| 59 params.logout_url = GURL(value); |
| 60 } else { |
| 61 DLOG(WARNING) << "Unexpected Gaia header attribute '" << key_name << "'."; |
| 62 } |
| 63 } |
| 64 |
| 65 return params; |
| 66 } |
| 67 |
| 14 bool DiceHeaderHelper::IsUrlEligibleForRequestHeader(const GURL& url) { | 68 bool DiceHeaderHelper::IsUrlEligibleForRequestHeader(const GURL& url) { |
| 15 if (switches::GetAccountConsistencyMethod() != | 69 if (switches::GetAccountConsistencyMethod() != |
| 16 switches::AccountConsistencyMethod::kDice) { | 70 switches::AccountConsistencyMethod::kDice) { |
| 17 return false; | 71 return false; |
| 18 } | 72 } |
| 19 return gaia::IsGaiaSignonRealm(url.GetOrigin()); | 73 return gaia::IsGaiaSignonRealm(url.GetOrigin()); |
| 20 } | 74 } |
| 21 | 75 |
| 22 std::string DiceHeaderHelper::BuildRequestHeader(bool is_header_request, | 76 std::string DiceHeaderHelper::BuildRequestHeader(bool is_header_request, |
| 23 const GURL& url, | 77 const GURL& url, |
| 24 const std::string& account_id, | 78 const std::string& account_id, |
| 25 int profile_mode_mask) { | 79 int profile_mode_mask) { |
| 26 return "client_id=" + GaiaUrls::GetInstance()->oauth2_chrome_client_id(); | 80 return "client_id=" + GaiaUrls::GetInstance()->oauth2_chrome_client_id(); |
| 27 } | 81 } |
| 28 | 82 |
| 29 } // namespace signin | 83 } // namespace signin |
| OLD | NEW |