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