Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Side by Side Diff: components/signin/core/browser/dice_header_helper.cc

Issue 2918403009: [Dice] Parse the Dice response header (Closed)
Patch Set: Remove logout url Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/strings/string_number_conversions.h"
7 #include "components/signin/core/common/profile_management_switches.h" 8 #include "components/signin/core/common/profile_management_switches.h"
8 #include "google_apis/gaia/gaia_auth_util.h" 9 #include "google_apis/gaia/gaia_auth_util.h"
9 #include "google_apis/gaia/gaia_urls.h" 10 #include "google_apis/gaia/gaia_urls.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
22 // Determines the Dice action that has been passed from Gaia in the header.
23 DiceAction GetDiceActionFromHeader(const std::string& value) {
24 if (value == "SIGNIN")
25 return DiceAction::SIGNIN;
26 else if (value == "SIGNOUT")
27 return DiceAction::SIGNOUT;
28 else if (value == "SINGLE_SESSION_SIGN_OUT")
29 return DiceAction::SINGLE_SESSION_SIGNOUT;
30 else
31 return DiceAction::NONE;
32 }
33
34 } // namespace
35
36 // static
37 DiceResponseParams DiceHeaderHelper::BuildDiceResponseParams(
38 const std::string& header_value) {
39 DCHECK(!header_value.empty());
40 DiceResponseParams params;
41 ResponseHeaderDictionary header_dictionary =
42 ParseAccountConsistencyResponseHeader(header_value);
43 ResponseHeaderDictionary::const_iterator it = header_dictionary.begin();
44 for (; it != header_dictionary.end(); ++it) {
45 const std::string key_name(it->first);
46 const std::string value(it->second);
47 if (key_name == kActionAttrName) {
48 params.user_intention = GetDiceActionFromHeader(value);
49 } else if (key_name == kIdAttrName) {
50 params.obfuscated_gaia_id = value;
51 } else if (key_name == kEmailAttrName) {
52 params.email = value;
53 } else if (key_name == kAuthUserAttrName) {
54 bool parse_success = base::StringToInt(value, &params.session_index);
55 if (!parse_success)
56 params.session_index = -1;
57 } else if (key_name == kAuthorizationCodeAttrName) {
58 params.authorization_code = value;
59 } else {
60 DLOG(WARNING) << "Unexpected Gaia header attribute '" << key_name << "'.";
61 }
62 }
63
64 if (params.obfuscated_gaia_id.empty() || params.email.empty() ||
65 params.session_index == -1) {
66 DLOG(WARNING) << "Missing parameters for Dice header.";
67 params.user_intention = DiceAction::NONE;
68 }
69
70 if (params.user_intention == DiceAction::SIGNIN &&
71 params.authorization_code.empty()) {
72 DLOG(WARNING) << "Missing authorization code for Dice SIGNIN.";
73 params.user_intention = DiceAction::NONE;
74 }
75
76 return params;
77 }
78
14 bool DiceHeaderHelper::IsUrlEligibleForRequestHeader(const GURL& url) { 79 bool DiceHeaderHelper::IsUrlEligibleForRequestHeader(const GURL& url) {
15 if (switches::GetAccountConsistencyMethod() != 80 if (switches::GetAccountConsistencyMethod() !=
16 switches::AccountConsistencyMethod::kDice) { 81 switches::AccountConsistencyMethod::kDice) {
17 return false; 82 return false;
18 } 83 }
19 return gaia::IsGaiaSignonRealm(url.GetOrigin()); 84 return gaia::IsGaiaSignonRealm(url.GetOrigin());
20 } 85 }
21 86
22 std::string DiceHeaderHelper::BuildRequestHeader(bool is_header_request, 87 std::string DiceHeaderHelper::BuildRequestHeader(bool is_header_request,
23 const GURL& url, 88 const GURL& url,
24 const std::string& account_id, 89 const std::string& account_id,
25 int profile_mode_mask) { 90 int profile_mode_mask) {
26 return "client_id=" + GaiaUrls::GetInstance()->oauth2_chrome_client_id(); 91 return "client_id=" + GaiaUrls::GetInstance()->oauth2_chrome_client_id();
27 } 92 }
28 93
29 } // namespace signin 94 } // namespace signin
OLDNEW
« no previous file with comments | « components/signin/core/browser/dice_header_helper.h ('k') | components/signin/core/browser/signin_header_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698