summaryrefslogtreecommitdiffstats
path: root/net/http/http_auth_handler_basic.cc
diff options
context:
space:
mode:
authorericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-27 03:19:42 +0000
committerericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-27 03:19:42 +0000
commitc3b35c2100dba30c517116bc9a5a4e4149c3a8e5 (patch)
treeff42c902c4ee9afd7864a2bda8e5e815a876bc76 /net/http/http_auth_handler_basic.cc
parente5be6612288df667ca6ae4a86060bc883a498eea (diff)
downloadchromium_src-c3b35c2100dba30c517116bc9a5a4e4149c3a8e5.zip
chromium_src-c3b35c2100dba30c517116bc9a5a4e4149c3a8e5.tar.gz
chromium_src-c3b35c2100dba30c517116bc9a5a4e4149c3a8e5.tar.bz2
Initial stab at http authentication (basic + digest) in new http stack.
General design: - class HttpAuth -- utility class for http-auth logic. - class HttpAuth::ChallengeTokenizer -- parsing of www-Authenticate headers. - class HttpAuthHandler -- base class for authentication schemes (inspired by nsIHttpAuthenticator) - class HttpAuthHandlerBasic : HttpAuthHandler -- logic for basic auth. - class HttpAuthHandlerDigest : HttpAuthHandler -- logic for digest auth. - The auth integration in HttpNetworkTransaction mimics that of HttpTransactionWinHttp: + HttpNetworkTransaction::ApplyAuth() -- set the authorization headers. + HttpNetworkTransaction::PopulateAuthChallenge() -- process the challenges. BUG=2346 Review URL: http://codereview.chromium.org/4063 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2658 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_auth_handler_basic.cc')
-rw-r--r--net/http/http_auth_handler_basic.cc46
1 files changed, 46 insertions, 0 deletions
diff --git a/net/http/http_auth_handler_basic.cc b/net/http/http_auth_handler_basic.cc
new file mode 100644
index 0000000..51c165c
--- /dev/null
+++ b/net/http/http_auth_handler_basic.cc
@@ -0,0 +1,46 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/http/http_auth_handler_basic.h"
+
+#include "base/string_util.h"
+#include "net/http/http_auth.h"
+#include "net/base/base64.h"
+
+namespace net {
+
+bool HttpAuthHandlerBasic::Init(std::string::const_iterator challenge_begin,
+ std::string::const_iterator challenge_end) {
+ scheme_ = "basic";
+ score_ = 1;
+
+ // Verify the challenge's auth-scheme.
+ HttpAuth::ChallengeTokenizer challenge_tok(challenge_begin, challenge_end);
+ if (!challenge_tok.valid() ||
+ !LowerCaseEqualsASCII(challenge_tok.scheme(), "basic"))
+ return false;
+
+ // Extract the realm.
+ while (challenge_tok.GetNext()) {
+ if (LowerCaseEqualsASCII(challenge_tok.name(), "realm"))
+ realm_ = challenge_tok.unquoted_value();
+ }
+
+ return challenge_tok.valid() && !realm_.empty();
+}
+
+std::string HttpAuthHandlerBasic::GenerateCredentials(
+ const std::wstring& username,
+ const std::wstring& password,
+ const HttpRequestInfo*,
+ const ProxyInfo*) {
+ // TODO(eroman): is this the right encoding of username/password?
+ std::string base64_username_password;
+ if (!Base64Encode(WideToUTF8(username) + ":" + WideToUTF8(password),
+ &base64_username_password))
+ return std::string(); // FAIL
+ return std::string("Basic ") + base64_username_password;
+}
+
+} // namespace net