OLD | NEW |
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/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 } | 73 } |
74 | 74 |
75 HttpAuth::AuthorizationResult HttpAuthHandlerBasic::HandleAnotherChallenge( | 75 HttpAuth::AuthorizationResult HttpAuthHandlerBasic::HandleAnotherChallenge( |
76 HttpAuthChallengeTokenizer* challenge) { | 76 HttpAuthChallengeTokenizer* challenge) { |
77 // Basic authentication is always a single round, so any responses | 77 // Basic authentication is always a single round, so any responses |
78 // should be treated as a rejection. However, if the new challenge | 78 // should be treated as a rejection. However, if the new challenge |
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) ? HttpAuth::AUTHORIZATION_RESULT_DIFFERENT_REALM |
84 HttpAuth::AUTHORIZATION_RESULT_DIFFERENT_REALM: | 84 : HttpAuth::AUTHORIZATION_RESULT_REJECT; |
85 HttpAuth::AUTHORIZATION_RESULT_REJECT; | |
86 } | 85 } |
87 | 86 |
88 int HttpAuthHandlerBasic::GenerateAuthTokenImpl( | 87 int HttpAuthHandlerBasic::GenerateAuthTokenImpl( |
89 const AuthCredentials* credentials, const HttpRequestInfo*, | 88 const AuthCredentials* credentials, |
90 const CompletionCallback&, std::string* auth_token) { | 89 const HttpRequestInfo*, |
| 90 const CompletionCallback&, |
| 91 std::string* auth_token) { |
91 DCHECK(credentials); | 92 DCHECK(credentials); |
92 // TODO(eroman): is this the right encoding of username/password? | 93 // TODO(eroman): is this the right encoding of username/password? |
93 std::string base64_username_password; | 94 std::string base64_username_password; |
94 base::Base64Encode(base::UTF16ToUTF8(credentials->username()) + ":" + | 95 base::Base64Encode(base::UTF16ToUTF8(credentials->username()) + ":" + |
95 base::UTF16ToUTF8(credentials->password()), | 96 base::UTF16ToUTF8(credentials->password()), |
96 &base64_username_password); | 97 &base64_username_password); |
97 *auth_token = "Basic " + base64_username_password; | 98 *auth_token = "Basic " + base64_username_password; |
98 return OK; | 99 return OK; |
99 } | 100 } |
100 | 101 |
(...skipping 14 matching lines...) Expand all Loading... |
115 // TODO(cbentzel): Move towards model of parsing in the factory | 116 // TODO(cbentzel): Move towards model of parsing in the factory |
116 // method and only constructing when valid. | 117 // method and only constructing when valid. |
117 scoped_ptr<HttpAuthHandler> tmp_handler(new HttpAuthHandlerBasic()); | 118 scoped_ptr<HttpAuthHandler> tmp_handler(new HttpAuthHandlerBasic()); |
118 if (!tmp_handler->InitFromChallenge(challenge, target, origin, net_log)) | 119 if (!tmp_handler->InitFromChallenge(challenge, target, origin, net_log)) |
119 return ERR_INVALID_RESPONSE; | 120 return ERR_INVALID_RESPONSE; |
120 handler->swap(tmp_handler); | 121 handler->swap(tmp_handler); |
121 return OK; | 122 return OK; |
122 } | 123 } |
123 | 124 |
124 } // namespace net | 125 } // namespace net |
OLD | NEW |