example/LastFmAuthApp/inc/sessionSP.h
author cgandhi
Mon, 11 Oct 2010 21:59:54 +0530
changeset 26 83d6a149c755
permissions -rw-r--r--
Submitting following changes - AuthApps for Last.fm and Twitter added API for checking ServiceAuthorization added for SMFCredMgrClient API added for forcefully removing credential details from SMFCredMgr Extra argument checks in SMfClient APIs APIs for service login and logout from SMFClient Redundant members removed from SmfServerSymbian DSM bug fixes Test Apps included
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
     1
/**
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
     2
* Copyright (c) 2010 Sasken Communication Technologies Ltd.
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
     3
* All rights reserved.
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
     4
* This component and the accompanying materials are made available
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
     5
* under the terms of the "{License}"
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
     6
* which accompanies  this distribution, and is available
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
     7
* at the URL "{LicenseUrl}".
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
     8
*
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
     9
* Initial Contributors:
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    10
* Narasimhulu Kavadapu, Sasken Communication Technologies Ltd - Initial contribution
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    11
*
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    12
* Contributors:
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    13
* Siddhartha Chandra, Sasken Communication Technologies Ltd
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    14
* Description:
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    15
* class to maintian session & all credential keys.
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    16
*/
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    17
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    18
#ifndef FBSESSION_H
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    19
#define FBSESSION_H
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    20
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    21
#include <QObject>
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    22
#include <QList>
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    23
#include <QString>
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    24
#include <QSettings>
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    25
#include <QDateTime>
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    26
#include "smfcredmgrclient.h"
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    27
#include "authAppConstants.h"
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    28
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    29
// FORWARD DECLARATIONS
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    30
class FBRequest;
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    31
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    32
const QString KFacebokkKeysFileName = "c://Data//FacebookKeys.txt";
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    33
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    34
///////////////////////////////////////////////////////////////////////////////////////////////////
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    35
/**
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    36
 * An FBSession represents a single user's authenticated session for a Facebook application.
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    37
 *
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    38
 * To create a session, you must use the session key of your application (which can
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    39
 * be found on the Facebook developer website).  You may then use the login dialog to ask
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    40
 * the user to enter their email address and password.  If successful, you will get back a
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    41
 * session key which can be used to make requests to the Facebook API.
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    42
 *
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    43
 * Session keys are cached and stored on the disk of the device so that you do not need to ask
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    44
 * the user to login every time they launch the app.  To restore the last active session, call the
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    45
 * resume method after instantiating your session.
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    46
 */
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    47
class FBSession : public QObject
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    48
{
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    49
    Q_OBJECT
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    50
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    51
private:
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    52
    /**
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    53
     * Your application's API key, as passed to the constructor.
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    54
     */
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    55
    QString iApiKey;
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    56
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    57
    /**
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    58
     * Your application's API secret, as passed to the constructor.
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    59
     */
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    60
    QString iApiSecret;
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    61
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    62
  /**
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    63
	 * The current user's Frob key.
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    64
	 */
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    65
	QString iToken;
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    66
	
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    67
	/**
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    68
	 * The user's Session Key
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    69
	 */
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    70
	QString iLastfmSessionKey;
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    71
	
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    72
	/**
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    73
	 * The user's Session Key
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    74
	 */
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    75
	QString iLastfmUserName;
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    76
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    77
    /**
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    78
      * The settings object used to restore session from the disk.
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    79
      */
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    80
    QSettings   iSettings;
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    81
    /**
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    82
      * The Credentail Object used to store auth data
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    83
      */
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    84
    SmfCredMgrClient* m_Client; 
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    85
    /**
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    86
      * Variable to store 
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    87
      */ 
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    88
    QString iCMRegToken;
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    89
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    90
signals: /* the signals ommitted by FBSession */
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    91
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    92
    /**
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    93
      * Called when session logged in sucessfully
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    94
      * @param SessionKey is the fb assigned session key
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    95
      */
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    96
    void sessionDidLogin (QString SessionKey);
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    97
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    98
    /**
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
    99
     * Called when a user closes the login dialog without logging in.
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   100
     */
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   101
    void sessionDidNotLogin ();
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   102
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   103
    /**
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   104
     * Called when a session is about to log out.
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   105
     * @param aUid is the fb assigned session id
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   106
     */
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   107
    void sessionWillLogout ();
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   108
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   109
    /**
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   110
     * Called when a session has logged out.
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   111
     */
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   112
    void sessionDidLogout ();
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   113
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   114
public: /* class functions */
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   115
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   116
    /**
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   117
     * The globally shared session instance.
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   118
     */
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   119
    static FBSession* session();
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   120
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   121
    /**
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   122
     * Sets the globally shared session instance.
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   123
     *
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   124
     * This session is not retained, so you are still responsible for retaining it yourself.  The
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   125
     * first session that is created is automatically stored here.
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   126
     */
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   127
    static void setSession(FBSession* aSession);
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   128
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   129
    /**
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   130
     * Constructs a session and stores it as the globally shared session instance.
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   131
     *
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   132
     * @param aSessionProxy a url to that proxies auth.getSession
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   133
     */
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   134
    static FBSession* sessionForApplication ( const QString& aKey, const QString& aSecret, const QString& aSessionProxy);
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   135
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   136
public: /* instance functions */
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   137
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   138
    /**
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   139
     * Constructs a session for an application.
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   140
     *
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   141
     * @param secret the application secret (optional)
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   142
     * @param getSessionProxy a url to that proxies auth.getSession (optional)
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   143
     */
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   144
    FBSession( const QString& aKey, const QString& aSecret, const QString& aSessionProxy );
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   145
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   146
    /**
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   147
      * Destructor
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   148
      */
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   149
    ~FBSession();
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   150
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   151
    /**
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   152
     * Saves Frob Key
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   153
     */
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   154
    void SaveToken ( const QString& aToken);
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   155
    
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   156
    /**
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   157
	 * Saves Session Key
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   158
	 */
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   159
	void SaveSession (const QString& session, const QString& name );
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   160
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   161
    /**
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   162
     * Resumes a previous session whose uid, session key, and secret are cached on disk.
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   163
     */
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   164
     bool resume();
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   165
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   166
    /**
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   167
     * Ends the current session and deletes the uid, session key, and secret from disk.
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   168
     */
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   169
    void logout();
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   170
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   171
    /**
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   172
     * Sends a fully configured request to the server for execution.
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   173
     */
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   174
    void send (FBRequest* aRequest);
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   175
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   176
    /**
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   177
      * @return const QString& http:// URL to the facebook REST server
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   178
      */
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   179
    const QString& apiURL() const;
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   180
    /**
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   181
      * @return const QString& the api secret
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   182
      */
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   183
    const QString& apiSecret() const { return iApiSecret; }
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   184
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   185
    /**
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   186
      * @return api key for this session
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   187
      */
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   188
    const QString& apiKey() const { return iApiKey; }
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   189
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   190
    /**
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   191
	  * @return the Frob key
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   192
	  */
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   193
	//const QString& apiTokenjKey() const { return iFrobKey; }
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   194
	
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   195
	/**
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   196
		  * @return the Api Token
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   197
	*/
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   198
	const QString& apiToken() const { return iToken; }
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   199
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   200
private:
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   201
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   202
    /**
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   203
      * Saves the fb connect session information to disk
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   204
      */
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   205
    void save();
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   206
    /**
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   207
      * Forgets any fb connect session information saved to disk
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   208
      */
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   209
    void unsave();
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   210
    /**
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   211
      * @param aRequest, the request to perform.
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   212
      * @param aEnqueue, if true add to queue if cant perform the request right now
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   213
      */
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   214
    bool performRequest(FBRequest* aRequest, bool aEnqueue);
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   215
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   216
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   217
};
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   218
83d6a149c755 Submitting following changes -
cgandhi
parents:
diff changeset
   219
#endif // FBSESSION_H