work on auth handling, still not right yet though
This commit is contained in:
parent
fcf50dc6d0
commit
f67e4c2104
3 changed files with 33 additions and 6 deletions
2
buildnum
2
buildnum
|
@ -1 +1 @@
|
||||||
16
|
26
|
27
src/Pnut.cpp
27
src/Pnut.cpp
|
@ -30,6 +30,7 @@ Pnut::Pnut()
|
||||||
req_id = 0;
|
req_id = 0;
|
||||||
before_id = 0;
|
before_id = 0;
|
||||||
since_id = 0;
|
since_id = 0;
|
||||||
|
authInProgress = false;
|
||||||
|
|
||||||
m_appSettings = new QSettings("Morgan McMillian", "Goober");
|
m_appSettings = new QSettings("Morgan McMillian", "Goober");
|
||||||
oauthRequest = new KQOAuthRequest;
|
oauthRequest = new KQOAuthRequest;
|
||||||
|
@ -40,6 +41,11 @@ Pnut::Pnut()
|
||||||
|
|
||||||
Q_ASSERT(auth_req);
|
Q_ASSERT(auth_req);
|
||||||
|
|
||||||
|
bool net_req = connect(oauthManager, SIGNAL(requestReady(QByteArray)),
|
||||||
|
this, SLOT(onRequestReady(QByteArray)));
|
||||||
|
|
||||||
|
Q_ASSERT(net_req);
|
||||||
|
|
||||||
bool conn_req = connect(oauthManager, SIGNAL(authorizedRequestReady(QByteArray,int)),
|
bool conn_req = connect(oauthManager, SIGNAL(authorizedRequestReady(QByteArray,int)),
|
||||||
this, SLOT(onAuthorizedRequestReady(QByteArray,int)));
|
this, SLOT(onAuthorizedRequestReady(QByteArray,int)));
|
||||||
|
|
||||||
|
@ -52,7 +58,7 @@ Pnut::~Pnut()
|
||||||
{
|
{
|
||||||
delete oauthRequest;
|
delete oauthRequest;
|
||||||
delete oauthManager;
|
delete oauthManager;
|
||||||
qDebug() << "Pnut destroyed,, I am death.";
|
qDebug() << "Pnut destroyed, I am death.";
|
||||||
}
|
}
|
||||||
|
|
||||||
int Pnut::sinceId() const
|
int Pnut::sinceId() const
|
||||||
|
@ -77,10 +83,14 @@ void Pnut::setBeforeId(const int& id)
|
||||||
|
|
||||||
void Pnut::authorize()
|
void Pnut::authorize()
|
||||||
{
|
{
|
||||||
|
if (authInProgress != true)
|
||||||
|
{
|
||||||
|
authInProgress = true;
|
||||||
QUrl url(PNUT_AUTH_URL);
|
QUrl url(PNUT_AUTH_URL);
|
||||||
KQOAuthParameters parameters;
|
KQOAuthParameters parameters;
|
||||||
parameters.insert("scope", "basic stream write_post follow update_profile presence");
|
parameters.insert("scope", "basic stream write_post follow update_profile presence");
|
||||||
oauthManager->getOauth2UserAuthorization(url, PNUT_CLIENT_ID, parameters);
|
oauthManager->getOauth2UserAuthorization(url, PNUT_CLIENT_ID, parameters);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pnut::getRequest(QUrl url, KQOAuthParameters parameters, int id)
|
void Pnut::getRequest(QUrl url, KQOAuthParameters parameters, int id)
|
||||||
|
@ -123,6 +133,21 @@ void Pnut::onAuthorizationReceived(QString token, QString verifier)
|
||||||
qDebug() << "- authorization error -";
|
qDebug() << "- authorization error -";
|
||||||
qDebug() << oauthManager->lastError();
|
qDebug() << oauthManager->lastError();
|
||||||
}
|
}
|
||||||
|
authInProgress = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pnut::onRequestReady(QByteArray data)
|
||||||
|
{
|
||||||
|
qDebug() << "- onRequestReady -";
|
||||||
|
switch (oauthManager->lastError())
|
||||||
|
{
|
||||||
|
case KQOAuthManager::NetworkError:
|
||||||
|
qDebug() << "- NetworkError - assume re-authorization";
|
||||||
|
m_appSettings->remove("access_token");
|
||||||
|
m_appSettings->remove("username");
|
||||||
|
authorize();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pnut::onAuthorizedRequestReady(QByteArray data, int id)
|
void Pnut::onAuthorizedRequestReady(QByteArray data, int id)
|
||||||
|
|
|
@ -73,6 +73,7 @@ public:
|
||||||
Q_INVOKABLE void getUserInfo();
|
Q_INVOKABLE void getUserInfo();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void onRequestReady(QByteArray data);
|
||||||
void onAuthorizedRequestReady(QByteArray data, int id);
|
void onAuthorizedRequestReady(QByteArray data, int id);
|
||||||
void onAuthorizationReceived(QString token, QString verifier);
|
void onAuthorizationReceived(QString token, QString verifier);
|
||||||
|
|
||||||
|
@ -94,6 +95,7 @@ private:
|
||||||
int req_id;
|
int req_id;
|
||||||
QMap<int,QString> req_map;
|
QMap<int,QString> req_map;
|
||||||
QMap<int,Pnut::RequestType> rtype_map;
|
QMap<int,Pnut::RequestType> rtype_map;
|
||||||
|
bool authInProgress;
|
||||||
|
|
||||||
void getRequest(QUrl url, KQOAuthParameters parameters, int id);
|
void getRequest(QUrl url, KQOAuthParameters parameters, int id);
|
||||||
void postRequest(QUrl url, KQOAuthParameters parameters, int id, QByteArray data);
|
void postRequest(QUrl url, KQOAuthParameters parameters, int id, QByteArray data);
|
||||||
|
|
Reference in a new issue