2
* This file is part of signond
4
* Copyright (C) 2016 Canonical Ltd.
6
* Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
8
* This library is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU Lesser General Public License
10
* version 2.1 as published by the Free Software Foundation.
12
* This library is distributed in the hope that it will be useful, but
13
* WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this library; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
23
#include <QCoreApplication>
24
#include <QDBusConnection>
26
#include <QDBusInterface>
27
#include <QDBusMessage>
28
#include <QTextStream>
31
#include "signond/signoncommon.h"
33
class AuthSession: public QObject
38
AuthSession(const QString &path);
42
void process(const QVariantMap &sessionData);
43
void onResponse(const QVariantMap &response);
44
void onError(const QDBusError &error);
48
QDBusInterface *m_dbus;
51
AuthSession::AuthSession(const QString &path):
55
m_dbus = new QDBusInterface(SIGNOND_SERVICE,
57
QLatin1String(SIGNOND_AUTH_SESSION_INTERFACE),
58
QDBusConnection::sessionBus());
61
AuthSession::~AuthSession()
66
void AuthSession::process(const QVariantMap &sessionData)
68
QVariantList arguments;
69
arguments += sessionData;
70
arguments += QStringLiteral("mech1");
72
QDBusMessage msg = QDBusMessage::createMethodCall(m_dbus->service(),
75
QStringLiteral("process"));
76
msg.setArguments(arguments);
78
m_dbus->connection().callWithCallback(msg, this,
79
SLOT(onResponse(const QVariantMap&)),
80
SLOT(onError(const QDBusError&)),
84
void AuthSession::onResponse(const QVariantMap &response)
86
// The called doesn't really care about the response value
89
QCoreApplication::quit();
92
void AuthSession::onError(const QDBusError &error)
94
m_out << "Error:" << error.name();
95
QCoreApplication::quit();
98
int main(int argc, char **argv)
100
QCoreApplication app(argc, argv);
104
QStringList args = QCoreApplication::arguments();
105
for (int i = 1; i < args.count(); i++) {
106
if (args[i] == "--sessionPath") {
107
sessionPath = args[++i];
111
AuthSession authSession(sessionPath);
113
QVariantMap sessionData {
114
{ "Secret", QStringLiteral("testSecret") },
115
{ "UserName", QStringLiteral("testUsername") },
117
authSession.process(sessionData);
119
QTimer::singleShot(10*1000, &app, SLOT(quit()));
125
#include "session_tool.moc"