diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2012-09-03 07:09:43 +0200 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2012-09-03 07:09:43 +0200 |
| commit | 59466bbc70b5b51f35458bddac6e7df4203c42b7 (patch) | |
| tree | f9b5b3ec191a8e9beee670469b13e80f6ec24723 /src | |
| parent | 2e95b3d002ef4bc50a239f21118165d3c6bd1f72 (diff) | |
| download | qxmpp-59466bbc70b5b51f35458bddac6e7df4203c42b7.tar.gz | |
Add support for X-MESSENGER-OAUTH2 authentication for Windows Live Messenger.
Diffstat (limited to 'src')
| -rw-r--r-- | src/base/QXmppSasl.cpp | 28 | ||||
| -rw-r--r-- | src/base/QXmppSasl_p.h | 11 | ||||
| -rw-r--r-- | src/client/QXmppConfiguration.cpp | 22 | ||||
| -rw-r--r-- | src/client/QXmppConfiguration.h | 3 | ||||
| -rw-r--r-- | src/client/QXmppOutgoingClient.cpp | 2 |
5 files changed, 65 insertions, 1 deletions
diff --git a/src/base/QXmppSasl.cpp b/src/base/QXmppSasl.cpp index 9e593cc0..6d1511cc 100644 --- a/src/base/QXmppSasl.cpp +++ b/src/base/QXmppSasl.cpp @@ -230,7 +230,7 @@ QXmppSaslClient::~QXmppSaslClient() QStringList QXmppSaslClient::availableMechanisms() { - return QStringList() << "PLAIN" << "DIGEST-MD5" << "ANONYMOUS" << "X-FACEBOOK-PLATFORM"; + return QStringList() << "PLAIN" << "DIGEST-MD5" << "ANONYMOUS" << "X-FACEBOOK-PLATFORM" << "X-MESSENGER-OAUTH2"; } /// Creates an SASL client for the given mechanism. @@ -245,6 +245,8 @@ QXmppSaslClient* QXmppSaslClient::create(const QString &mechanism, QObject *pare return new QXmppSaslClientAnonymous(parent); } else if (mechanism == "X-FACEBOOK-PLATFORM") { return new QXmppSaslClientFacebook(parent); + } else if (mechanism == "X-MESSENGER-OAUTH2") { + return new QXmppSaslClientWindowsLive(parent); } else { return 0; } @@ -478,6 +480,30 @@ bool QXmppSaslClientPlain::respond(const QByteArray &challenge, QByteArray &resp } } +QXmppSaslClientWindowsLive::QXmppSaslClientWindowsLive(QObject *parent) + : QXmppSaslClient(parent) + , m_step(0) +{ +} + +QString QXmppSaslClientWindowsLive::mechanism() const +{ + return "X-MESSENGER-OAUTH2"; +} + +bool QXmppSaslClientWindowsLive::respond(const QByteArray &challenge, QByteArray &response) +{ + if (m_step == 0) { + // send initial response + response = QByteArray::fromBase64(password().toLatin1()); + m_step++; + return true; + } else { + warning("QXmppSaslClientWindowsLive : Invalid step"); + return false; + } +} + class QXmppSaslServerPrivate { public: diff --git a/src/base/QXmppSasl_p.h b/src/base/QXmppSasl_p.h index ba2f66ba..153c4544 100644 --- a/src/base/QXmppSasl_p.h +++ b/src/base/QXmppSasl_p.h @@ -251,6 +251,17 @@ private: int m_step; }; +class QXmppSaslClientWindowsLive : public QXmppSaslClient +{ +public: + QXmppSaslClientWindowsLive(QObject *parent = 0); + QString mechanism() const; + bool respond(const QByteArray &challenge, QByteArray &response); + +private: + int m_step; +}; + class QXmppSaslServerAnonymous : public QXmppSaslServer { public: diff --git a/src/client/QXmppConfiguration.cpp b/src/client/QXmppConfiguration.cpp index 336630ee..eb30e0df 100644 --- a/src/client/QXmppConfiguration.cpp +++ b/src/client/QXmppConfiguration.cpp @@ -43,6 +43,9 @@ public: QString facebookAccessToken; QString facebookAppId; + // Windows Live + QString windowsLiveAccessToken; + // default is false bool autoAcceptSubscriptions; // default is true @@ -328,6 +331,25 @@ void QXmppConfiguration::setFacebookAppId(const QString& appId) d->facebookAppId = appId; } +/// Returns the access token used for X-MESSENGER-OAUTH2 authentication. + +QString QXmppConfiguration::windowsLiveAccessToken() const +{ + return d->windowsLiveAccessToken; +} + +/// Sets the access token used for X-MESSENGER-OAUTH2 authentication. +/// +/// This token is returned by Windows Live at the end of the OAuth authentication +/// process. +/// +/// \param accessToken + +void QXmppConfiguration::setWindowsLiveAccessToken(const QString& accessToken) +{ + d->windowsLiveAccessToken = accessToken; +} + /// Returns the auto-accept-subscriptions-request configuration. /// /// \return boolean value diff --git a/src/client/QXmppConfiguration.h b/src/client/QXmppConfiguration.h index c578cd74..dc384520 100644 --- a/src/client/QXmppConfiguration.h +++ b/src/client/QXmppConfiguration.h @@ -107,6 +107,9 @@ public: QString facebookAppId() const; void setFacebookAppId(const QString&); + QString windowsLiveAccessToken() const; + void setWindowsLiveAccessToken(const QString &accessToken); + bool autoAcceptSubscriptions() const; void setAutoAcceptSubscriptions(bool); diff --git a/src/client/QXmppOutgoingClient.cpp b/src/client/QXmppOutgoingClient.cpp index 3c480155..c3e6c1f9 100644 --- a/src/client/QXmppOutgoingClient.cpp +++ b/src/client/QXmppOutgoingClient.cpp @@ -395,6 +395,8 @@ void QXmppOutgoingClient::handleStanza(const QDomElement &nodeRecv) if (d->saslClient->mechanism() == "X-FACEBOOK-PLATFORM") { d->saslClient->setUsername(configuration().facebookAppId()); d->saslClient->setPassword(configuration().facebookAccessToken()); + } else if (d->saslClient->mechanism() == "X-MESSENGER-OAUTH2") { + d->saslClient->setPassword(configuration().windowsLiveAccessToken()); } else { d->saslClient->setUsername(configuration().user()); d->saslClient->setPassword(configuration().password()); |
