Comments, Code and Qt. Some words about the wonderful world of software engineering

6Nov/100

Advanced use of kQOAuth

In my previous post I introduced the kQOAuth library and how to use its convenient authorization process. I believe this is what 90% of the users want to do anyway, but I also wanted to write about the rest of the features the library provides so that you can be in total control of what is going on. Also, if you are interested in custom reply parameters sent by the service, you need to connect to some signals to retrieve them. The two main components of kQOAuth are KQOAuthManager and KQOAuthRequest. KQOAuthManager executes OAuth requests KQOAuthRequests, parses the replies and emits Qt signals describing the process of the OAuth authentication. It will keep track of the state of the authorization process which means that the provided convenience methods can be used to achieve the steps in OAuth authentication without explicitely constructing each request. KQOAuthRequest is the class that represent each step of the OAuth process. KQOAuthManager executes the given OAuth request. KQOAuthRequest will also take care of parameter normalization, generating the needed authorization header and most importantly, generates a OAuth signature. Internally KQOAuthManager constructs KQOAuthRequests so nothing prevents you from doing the same thing explicitly. By reading my previous post you will probably get the idea how to use KQOAuthManager and KQOAuthRequest. For more complete documentation, please see the README file.

KQOAuthManager methods

Some methods I didn't cover in my previous post that you are probably interested in. KQOAuthError lastError() - This will return the previous error code describing any most recent error that happened. bool hasTemporaryToken() - Returns true if the temporary token is received successfully. bool isVerified() - Returns true if the user has succesfully verified us to access the protected resources. Otherwise returns false. bool isAuthorized() - Returns true if we have access tokens to access the protected resources. Otherwise returns false.

KQOAuthManager signals

If you want to control the authorization process from your own application or if you want to retrieve service provider's reply parameters, you can use the following Qt signals for that. void requestReady(QMultiMap<QString, QString> replyParameters) - This signal is emited after the service replied to the request and the reply has been processed by KQOAuthManager. It will return all the request response parameters in a QMultiMap, where the first parameter is the name and the second parameter is the value. void receivedToken(QString oauth_token, QString oauth_token_secret) - This signal is emitted after a successful request for temporary tokens or access tokens. The requested tokens are sent as parameters in this signal. void temporaryTokenReceived(QString oauth_token, QString oauth_token_secret) - This signal is emitted after a successful request for temporary tokens. The tokens are sent as parameters to this signal. void authorizationReceived(QString oauth_token, QString oauth_verifier) - This signal is emitted after the user has concluded the authorization request step in the service provider's website.  Note that setHandleUserAuthorization(true) must be called when requesting for the temporary token. void accessTokenReceived(QString oauth_token, QString oauth_token_secret) - This signal is emited after a successful request for access tokens. The requested tokens are sent as parameters in this signal. These tokens are necessary when accessing protected resources.

Official page

I created a separate page for kQOAuth. You can visit it at http://www.johanpaul.com/blog/kqoauth/

Technorati Tags: , ,