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

Side by Side Diff: net/http/http_auth_handler_basic.cc

Issue 8340026: Use AuthCredentials throughout the network stack instead of username/password. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: mac compile fix Created 9 years, 1 month 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "net/http/http_auth_handler_basic.h" 5 #include "net/http/http_auth_handler_basic.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/i18n/icu_string_conversions.h" 10 #include "base/i18n/icu_string_conversions.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // is for a different realm, then indicate the realm change. 79 // is for a different realm, then indicate the realm change.
80 std::string realm; 80 std::string realm;
81 if (!ParseRealm(*challenge, &realm)) 81 if (!ParseRealm(*challenge, &realm))
82 return HttpAuth::AUTHORIZATION_RESULT_INVALID; 82 return HttpAuth::AUTHORIZATION_RESULT_INVALID;
83 return (realm_ != realm)? 83 return (realm_ != realm)?
84 HttpAuth::AUTHORIZATION_RESULT_DIFFERENT_REALM: 84 HttpAuth::AUTHORIZATION_RESULT_DIFFERENT_REALM:
85 HttpAuth::AUTHORIZATION_RESULT_REJECT; 85 HttpAuth::AUTHORIZATION_RESULT_REJECT;
86 } 86 }
87 87
88 int HttpAuthHandlerBasic::GenerateAuthTokenImpl( 88 int HttpAuthHandlerBasic::GenerateAuthTokenImpl(
89 const string16* username, 89 const AuthCredentials* credentials,
90 const string16* password,
91 const HttpRequestInfo*, 90 const HttpRequestInfo*,
92 OldCompletionCallback*, 91 OldCompletionCallback*,
93 std::string* auth_token) { 92 std::string* auth_token) {
93 DCHECK(credentials);
94 // TODO(eroman): is this the right encoding of username/password? 94 // TODO(eroman): is this the right encoding of username/password?
95 std::string base64_username_password; 95 std::string base64_username_password;
96 if (!base::Base64Encode(UTF16ToUTF8(*username) + ":" + UTF16ToUTF8(*password), 96 if (!base::Base64Encode(
97 &base64_username_password)) { 97 UTF16ToUTF8(credentials->username()) + ":" +
98 UTF16ToUTF8(credentials->password()),
99 &base64_username_password)) {
98 LOG(ERROR) << "Unexpected problem Base64 encoding."; 100 LOG(ERROR) << "Unexpected problem Base64 encoding.";
99 return ERR_UNEXPECTED; 101 return ERR_UNEXPECTED;
100 } 102 }
101 *auth_token = "Basic " + base64_username_password; 103 *auth_token = "Basic " + base64_username_password;
102 return OK; 104 return OK;
103 } 105 }
104 106
105 HttpAuthHandlerBasic::Factory::Factory() { 107 HttpAuthHandlerBasic::Factory::Factory() {
106 } 108 }
107 109
(...skipping 11 matching lines...) Expand all
119 // TODO(cbentzel): Move towards model of parsing in the factory 121 // TODO(cbentzel): Move towards model of parsing in the factory
120 // method and only constructing when valid. 122 // method and only constructing when valid.
121 scoped_ptr<HttpAuthHandler> tmp_handler(new HttpAuthHandlerBasic()); 123 scoped_ptr<HttpAuthHandler> tmp_handler(new HttpAuthHandlerBasic());
122 if (!tmp_handler->InitFromChallenge(challenge, target, origin, net_log)) 124 if (!tmp_handler->InitFromChallenge(challenge, target, origin, net_log))
123 return ERR_INVALID_RESPONSE; 125 return ERR_INVALID_RESPONSE;
124 handler->swap(tmp_handler); 126 handler->swap(tmp_handler);
125 return OK; 127 return OK;
126 } 128 }
127 129
128 } // namespace net 130 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698