| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "jingle/notifier/communicator/gaia_token_pre_xmpp_auth.h" | 5 #include "jingle/notifier/communicator/gaia_token_pre_xmpp_auth.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/basictypes.h" |
| 9 #include "talk/base/socketaddress.h" | 10 #include "talk/base/socketaddress.h" |
| 10 #include "talk/xmpp/constants.h" | 11 #include "talk/xmpp/constants.h" |
| 11 #include "talk/xmpp/saslcookiemechanism.h" | 12 #include "talk/xmpp/saslcookiemechanism.h" |
| 12 | 13 |
| 13 namespace notifier { | 14 namespace notifier { |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 17 |
| 16 const char kGaiaAuthMechanism[] = "X-GOOGLE-TOKEN"; | 18 const char kGaiaAuthMechanism[] = "X-GOOGLE-TOKEN"; |
| 19 |
| 20 class GaiaCookieMechanism : public buzz::SaslCookieMechanism { |
| 21 public: |
| 22 GaiaCookieMechanism(const std::string & mechanism, |
| 23 const std::string & username, |
| 24 const std::string & cookie, |
| 25 const std::string & token_service) |
| 26 : buzz::SaslCookieMechanism( |
| 27 mechanism, username, cookie, token_service) {} |
| 28 |
| 29 virtual ~GaiaCookieMechanism() {} |
| 30 |
| 31 virtual buzz::XmlElement* StartSaslAuth() { |
| 32 buzz::XmlElement* auth = buzz::SaslCookieMechanism::StartSaslAuth(); |
| 33 // These attributes are necessary for working with non-gmail gaia |
| 34 // accounts. |
| 35 const std::string NS_GOOGLE_AUTH_PROTOCOL( |
| 36 "http://www.google.com/talk/protocol/auth"); |
| 37 const buzz::QName QN_GOOGLE_ALLOW_GENERATED_JID_XMPP_LOGIN( |
| 38 true, NS_GOOGLE_AUTH_PROTOCOL, "allow-generated-jid"); |
| 39 const buzz::QName QN_GOOGLE_AUTH_CLIENT_USES_FULL_BIND_RESULT( |
| 40 true, NS_GOOGLE_AUTH_PROTOCOL, "client-uses-full-bind-result"); |
| 41 auth->SetAttr(QN_GOOGLE_ALLOW_GENERATED_JID_XMPP_LOGIN, "true"); |
| 42 auth->SetAttr(QN_GOOGLE_AUTH_CLIENT_USES_FULL_BIND_RESULT, "true"); |
| 43 return auth; |
| 44 } |
| 45 |
| 46 private: |
| 47 DISALLOW_COPY_AND_ASSIGN(GaiaCookieMechanism); |
| 48 }; |
| 49 |
| 17 } // namespace | 50 } // namespace |
| 18 | 51 |
| 19 GaiaTokenPreXmppAuth::GaiaTokenPreXmppAuth( | 52 GaiaTokenPreXmppAuth::GaiaTokenPreXmppAuth( |
| 20 const std::string& username, | 53 const std::string& username, |
| 21 const std::string& token, | 54 const std::string& token, |
| 22 const std::string& token_service) | 55 const std::string& token_service) |
| 23 : username_(username), | 56 : username_(username), |
| 24 token_(token), | 57 token_(token), |
| 25 token_service_(token_service) { } | 58 token_service_(token_service) { } |
| 26 | 59 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 const std::vector<std::string> & mechanisms, bool encrypted) { | 95 const std::vector<std::string> & mechanisms, bool encrypted) { |
| 63 return (std::find(mechanisms.begin(), | 96 return (std::find(mechanisms.begin(), |
| 64 mechanisms.end(), kGaiaAuthMechanism) != | 97 mechanisms.end(), kGaiaAuthMechanism) != |
| 65 mechanisms.end()) ? kGaiaAuthMechanism : ""; | 98 mechanisms.end()) ? kGaiaAuthMechanism : ""; |
| 66 } | 99 } |
| 67 | 100 |
| 68 buzz::SaslMechanism* GaiaTokenPreXmppAuth::CreateSaslMechanism( | 101 buzz::SaslMechanism* GaiaTokenPreXmppAuth::CreateSaslMechanism( |
| 69 const std::string& mechanism) { | 102 const std::string& mechanism) { |
| 70 if (mechanism != kGaiaAuthMechanism) | 103 if (mechanism != kGaiaAuthMechanism) |
| 71 return NULL; | 104 return NULL; |
| 72 return new buzz::SaslCookieMechanism( | 105 return new GaiaCookieMechanism( |
| 73 kGaiaAuthMechanism, username_, token_, token_service_); | 106 kGaiaAuthMechanism, username_, token_, token_service_); |
| 74 } | 107 } |
| 75 | 108 |
| 76 } // namespace notifier | 109 } // namespace notifier |
| OLD | NEW |