Commit 245d8046 authored by Jesus Fernandez's avatar Jesus Fernandez

HTTP reply handler

parent 7baf116f
......@@ -53,6 +53,15 @@
QT_BEGIN_NAMESPACE
/*!
\class QOAuthHttpServerReplyHandler
\brief The QOAuthHttpServerReplyHandler implements a minimal HTTP Server to receive the
callbacks from the browser to retrieve the OAuth verifier.
This class should be used when the application is being executed in a device with the
possibility to allow the users to introduce their credentials in the authorization URL.
*/
QOAuthHttpServerReplyHandlerPrivate::QOAuthHttpServerReplyHandlerPrivate(quint16 port)
: text(QObject::tr("Callback received. Feel free to close this page."))
{
......@@ -103,14 +112,17 @@ void QOAuthHttpServerReplyHandlerPrivate::_q_answerClient()
socket->disconnectFromHost();
}
/*!
Constructs a QOAuthHttpServerReplyHandler with parent \a parent using a random available port.
*/
QOAuthHttpServerReplyHandler::QOAuthHttpServerReplyHandler(QObject *parent)
: QOAuthOobReplyHandler(*new QOAuthHttpServerReplyHandlerPrivate(0), parent)
{
Q_D(QOAuthHttpServerReplyHandler);
d->connect(&d->httpServer, &QTcpServer::newConnection,
d, &QOAuthHttpServerReplyHandlerPrivate::_q_clientConnected);
}
: QOAuthHttpServerReplyHandler(0, parent)
{}
/*!
Constructs a QOAuthHttpServerReplyHandler with parent \a parent using the port \a port if it is
available.
*/
QOAuthHttpServerReplyHandler::QOAuthHttpServerReplyHandler(quint16 port, QObject *parent)
: QOAuthOobReplyHandler(*new QOAuthHttpServerReplyHandlerPrivate(port), parent)
{
......@@ -119,9 +131,15 @@ QOAuthHttpServerReplyHandler::QOAuthHttpServerReplyHandler(quint16 port, QObject
d, &QOAuthHttpServerReplyHandlerPrivate::_q_clientConnected);
}
/*!
Destroys the object.
*/
QOAuthHttpServerReplyHandler::~QOAuthHttpServerReplyHandler()
{}
/*!
Returns the URL as a string with the address used to send the OAuth verifier from the server.
*/
QString QOAuthHttpServerReplyHandler::callback() const
{
Q_D(const QOAuthHttpServerReplyHandler);
......@@ -131,24 +149,20 @@ QString QOAuthHttpServerReplyHandler::callback() const
return url.toString(QUrl::EncodeDelimiters);
}
QString QOAuthHttpServerReplyHandler::callbackText() const
{
Q_D(const QOAuthHttpServerReplyHandler);
return d->text;
}
void QOAuthHttpServerReplyHandler::setCallbackText(const QString &text)
{
Q_D(QOAuthHttpServerReplyHandler);
d->text = text;
}
/*!
Returns the port being used by the server.
*/
quint16 QOAuthHttpServerReplyHandler::port() const
{
Q_D(const QOAuthHttpServerReplyHandler);
return d->httpServer.serverPort();
}
/*!
Starts listening in the selected port.
Returns \c true on success; otherwise returns \c false.
*/
bool QOAuthHttpServerReplyHandler::listen(quint16 port)
{
Q_D(QOAuthHttpServerReplyHandler);
......
......@@ -60,9 +60,6 @@ public:
virtual QString callback() const override;
QString callbackText() const;
void setCallbackText(const QString &text);
quint16 port() const;
bool listen(quint16 port = 0);
......
......@@ -53,7 +53,7 @@ QT_BEGIN_NAMESPACE
the OAuth verifier from the server.
This class should be used when the application is being executed in a device without the
possibility to allow the user to display the authorization URL and introduce his credentials
possibility to allow the users to display the authorization URL and introduce their credentials
manually.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment