work on auth handling, still not right yet though

This commit is contained in:
Morgan McMillian 2016-09-23 13:43:12 -07:00
parent fcf50dc6d0
commit f67e4c2104
3 changed files with 33 additions and 6 deletions

View file

@ -1 +1 @@
16
26

View file

@ -30,6 +30,7 @@ Pnut::Pnut()
req_id = 0;
before_id = 0;
since_id = 0;
authInProgress = false;
m_appSettings = new QSettings("Morgan McMillian", "Goober");
oauthRequest = new KQOAuthRequest;
@ -40,6 +41,11 @@ Pnut::Pnut()
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)),
this, SLOT(onAuthorizedRequestReady(QByteArray,int)));
@ -52,7 +58,7 @@ Pnut::~Pnut()
{
delete oauthRequest;
delete oauthManager;
qDebug() << "Pnut destroyed,, I am death.";
qDebug() << "Pnut destroyed, I am death.";
}
int Pnut::sinceId() const
@ -77,10 +83,14 @@ void Pnut::setBeforeId(const int& id)
void Pnut::authorize()
{
QUrl url(PNUT_AUTH_URL);
KQOAuthParameters parameters;
parameters.insert("scope", "basic stream write_post follow update_profile presence");
oauthManager->getOauth2UserAuthorization(url, PNUT_CLIENT_ID, parameters);
if (authInProgress != true)
{
authInProgress = true;
QUrl url(PNUT_AUTH_URL);
KQOAuthParameters parameters;
parameters.insert("scope", "basic stream write_post follow update_profile presence");
oauthManager->getOauth2UserAuthorization(url, PNUT_CLIENT_ID, parameters);
}
}
void Pnut::getRequest(QUrl url, KQOAuthParameters parameters, int id)
@ -123,6 +133,21 @@ void Pnut::onAuthorizationReceived(QString token, QString verifier)
qDebug() << "- authorization error -";
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)

View file

@ -73,6 +73,7 @@ public:
Q_INVOKABLE void getUserInfo();
public slots:
void onRequestReady(QByteArray data);
void onAuthorizedRequestReady(QByteArray data, int id);
void onAuthorizationReceived(QString token, QString verifier);
@ -94,6 +95,7 @@ private:
int req_id;
QMap<int,QString> req_map;
QMap<int,Pnut::RequestType> rtype_map;
bool authInProgress;
void getRequest(QUrl url, KQOAuthParameters parameters, int id);
void postRequest(QUrl url, KQOAuthParameters parameters, int id, QByteArray data);