saslcookiemechanism.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright 2004 The WebRTC Project Authors. All rights reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef THIRD_PARTY_LIBJINGLE_XMPP_XMPP_SASLCOOKIEMECHANISM_H_
  11. #define THIRD_PARTY_LIBJINGLE_XMPP_XMPP_SASLCOOKIEMECHANISM_H_
  12. #include "third_party/libjingle_xmpp/xmllite/qname.h"
  13. #include "third_party/libjingle_xmpp/xmllite/xmlelement.h"
  14. #include "third_party/libjingle_xmpp/xmpp/constants.h"
  15. #include "third_party/libjingle_xmpp/xmpp/saslmechanism.h"
  16. namespace jingle_xmpp {
  17. class SaslCookieMechanism : public SaslMechanism {
  18. public:
  19. SaslCookieMechanism(const std::string & mechanism,
  20. const std::string & username,
  21. const std::string & cookie,
  22. const std::string & token_service)
  23. : mechanism_(mechanism),
  24. username_(username),
  25. cookie_(cookie),
  26. token_service_(token_service) {}
  27. SaslCookieMechanism(const std::string & mechanism,
  28. const std::string & username,
  29. const std::string & cookie)
  30. : mechanism_(mechanism),
  31. username_(username),
  32. cookie_(cookie),
  33. token_service_("") {}
  34. virtual std::string GetMechanismName() { return mechanism_; }
  35. virtual XmlElement * StartSaslAuth() {
  36. // send initial request
  37. XmlElement * el = new XmlElement(QN_SASL_AUTH, true);
  38. el->AddAttr(QN_MECHANISM, mechanism_);
  39. if (!token_service_.empty()) {
  40. el->AddAttr(QN_GOOGLE_AUTH_SERVICE, token_service_);
  41. }
  42. std::string credential;
  43. credential.append("\0", 1);
  44. credential.append(username_);
  45. credential.append("\0", 1);
  46. credential.append(cookie_);
  47. el->AddText(Base64Encode(credential));
  48. return el;
  49. }
  50. private:
  51. std::string mechanism_;
  52. std::string username_;
  53. std::string cookie_;
  54. std::string token_service_;
  55. };
  56. }
  57. #endif // THIRD_PARTY_LIBJINGLE_XMPP_XMPP_SASLCOOKIEMECHANISM_H_