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
3 // found in the LICENSE file.
5 #include "jingle/notifier/base/gaia_token_pre_xmpp_auth.h"
9 #include "base/basictypes.h"
10 #include "base/logging.h"
11 #include "webrtc/base/socketaddress.h"
12 #include "webrtc/libjingle/xmpp/constants.h"
13 #include "webrtc/libjingle/xmpp/saslcookiemechanism.h"
19 class GaiaCookieMechanism
: public buzz::SaslCookieMechanism
{
21 GaiaCookieMechanism(const std::string
& mechanism
,
22 const std::string
& username
,
23 const std::string
& cookie
,
24 const std::string
& token_service
)
25 : buzz::SaslCookieMechanism(
26 mechanism
, username
, cookie
, token_service
) {}
28 ~GaiaCookieMechanism() override
{}
30 buzz::XmlElement
* StartSaslAuth() override
{
31 buzz::XmlElement
* auth
= buzz::SaslCookieMechanism::StartSaslAuth();
32 // These attributes are necessary for working with non-gmail gaia
34 const std::string
NS_GOOGLE_AUTH_PROTOCOL(
35 "http://www.google.com/talk/protocol/auth");
36 const buzz::QName
QN_GOOGLE_ALLOW_GENERATED_JID_XMPP_LOGIN(
37 NS_GOOGLE_AUTH_PROTOCOL
, "allow-generated-jid");
38 const buzz::QName
QN_GOOGLE_AUTH_CLIENT_USES_FULL_BIND_RESULT(
39 NS_GOOGLE_AUTH_PROTOCOL
, "client-uses-full-bind-result");
40 auth
->SetAttr(QN_GOOGLE_ALLOW_GENERATED_JID_XMPP_LOGIN
, "true");
41 auth
->SetAttr(QN_GOOGLE_AUTH_CLIENT_USES_FULL_BIND_RESULT
, "true");
46 DISALLOW_COPY_AND_ASSIGN(GaiaCookieMechanism
);
51 GaiaTokenPreXmppAuth::GaiaTokenPreXmppAuth(
52 const std::string
& username
,
53 const std::string
& token
,
54 const std::string
& token_service
,
55 const std::string
& auth_mechanism
)
56 : username_(username
),
58 token_service_(token_service
),
59 auth_mechanism_(auth_mechanism
) {
60 DCHECK(!auth_mechanism_
.empty());
63 GaiaTokenPreXmppAuth::~GaiaTokenPreXmppAuth() { }
65 void GaiaTokenPreXmppAuth::StartPreXmppAuth(
67 const rtc::SocketAddress
& server
,
68 const rtc::CryptString
& pass
,
69 const std::string
& auth_mechanism
,
70 const std::string
& auth_token
) {
74 bool GaiaTokenPreXmppAuth::IsAuthDone() const {
78 bool GaiaTokenPreXmppAuth::IsAuthorized() const {
82 bool GaiaTokenPreXmppAuth::HadError() const {
86 int GaiaTokenPreXmppAuth::GetError() const {
90 buzz::CaptchaChallenge
GaiaTokenPreXmppAuth::GetCaptchaChallenge() const {
91 return buzz::CaptchaChallenge();
94 std::string
GaiaTokenPreXmppAuth::GetAuthToken() const {
98 std::string
GaiaTokenPreXmppAuth::GetAuthMechanism() const {
99 return auth_mechanism_
;
102 std::string
GaiaTokenPreXmppAuth::ChooseBestSaslMechanism(
103 const std::vector
<std::string
> & mechanisms
, bool encrypted
) {
104 return (std::find(mechanisms
.begin(), mechanisms
.end(), auth_mechanism_
) !=
110 buzz::SaslMechanism
* GaiaTokenPreXmppAuth::CreateSaslMechanism(
111 const std::string
& mechanism
) {
112 if (mechanism
== auth_mechanism_
)
113 return new GaiaCookieMechanism(
114 mechanism
, username_
, token_
, token_service_
);
118 } // namespace notifier