Hi,
I have to create an application in which the user will provide a username and a password to connect to a web server and I have to do it with oAuth2.0.
So I created the following (by looking at Facebook and Twitter demo provided with oAuth).
const char CLIENT_ID[] = "...";
const char CLIENT_SECRET[] = "...";
const char REQUEST_URL[] = "...";
const char TOKEN_URL[] = "...";
oAuthClass
::oAuthClass(QObject *parent
) :{
O2* o2Auth = new O2(this);
o2Auth->setClientId(CLIENT_ID);
o2Auth->setClientSecret(CLIENT_SECRET);
o2Auth->setRequestUrl(REQUEST_URL);
o2Auth->setTokenUrl(TOKEN_URL);
// Create a store object for writing the received tokens
O2SettingsStore *store = new O2SettingsStore(O2_ENCRYPTION_KEY);
store->setGroupKey("oAuth");
o2Auth->setStore(store);
}
const char CLIENT_ID[] = "...";
const char CLIENT_SECRET[] = "...";
const char REQUEST_URL[] = "...";
const char TOKEN_URL[] = "...";
oAuthClass::oAuthClass(QObject *parent) :
QObject(parent)
{
O2* o2Auth = new O2(this);
o2Auth->setClientId(CLIENT_ID);
o2Auth->setClientSecret(CLIENT_SECRET);
o2Auth->setRequestUrl(REQUEST_URL);
o2Auth->setTokenUrl(TOKEN_URL);
// Create a store object for writing the received tokens
O2SettingsStore *store = new O2SettingsStore(O2_ENCRYPTION_KEY);
store->setGroupKey("oAuth");
o2Auth->setStore(store);
}
To copy to clipboard, switch view to plain text mode
And I am completely stuck there , I don't know what to do .
I think that I have to use the O2Requestor class which permits to create post request. Something like :
QNetworkAccessManager *manager;
O2Requestor* o2Requestor = new O2Requestor(manager,o2Auth);
QNetworkRequest* request = new QNetworkRequest(...);
/* I have the informations for the header
{ { "Authorization", "Basic <CLIENT_ID:CLIENT_SECRET>" },
{ "ContentType", "x-www-form-urlencoded" },
{ "grant_type", "password" },
{ "username", "<username>" },
{ "password", "<userpassword>" } }
so I can create a post request.
*/
o2Requestor->post(request, ...);
QNetworkAccessManager *manager;
O2Requestor* o2Requestor = new O2Requestor(manager,o2Auth);
QNetworkRequest* request = new QNetworkRequest(...);
/* I have the informations for the header
{ { "Authorization", "Basic <CLIENT_ID:CLIENT_SECRET>" },
{ "ContentType", "x-www-form-urlencoded" },
{ "grant_type", "password" },
{ "username", "<username>" },
{ "password", "<userpassword>" } }
so I can create a post request.
*/
o2Requestor->post(request, ...);
To copy to clipboard, switch view to plain text mode
So are those steps good or am I wrond?
In addition, there is a lot of signals / slots in O2 class. I think I have to use them if I want to know if the connection is ok, if the token must be refreshed, ...
(If you knwon a good tutorial about how to use oAuth2.0 in Qt C++, I would appreciate a lot )
Thanks.
Bookmarks