Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Desktop app with Facebook OAuth [Qt5.1] [Qt Quick Controls]
Ghost last edited by
I am getting confused on how to implement access_token retrieval from Facebook.
This is how I have thought it out:
- An OAuthorizer class, which takes care of the OAuth authentication. It initiates launch of a WebView window which will ask user to authenticate my app. On successful authentication, this class will store and provide a short-lived user access_token provided by Facebook. This class's authorize() method will have to launch QML window, thus involving a bit of UI code.
- TokenService class contains methods that retrieves different types of access_tokens based on the short-lived user access_token - like long-lived user access_token, page_token, etc.) This would be a pure C++ class without having to deal with any QML component.
Here is a rough sketch of the code. Note that it might not be syntactically correct - I wrote it on the fly.
class OAuthorizer :: QObject
QString accessToken() const;
void authorize(); // This method will launch a QML component containing WebView, which will authenticate and emit an authSuccessful signal.
void onSuccessfulAuth(const QUrl &url); // This slot will be invoked by authSuccessful signal and will parse the redirected URL for short-lived access_token.
// Other fields like redirectUrl, facebookAuthUrl, appId.
class TokenService :: QObject
QString fetchLongLivedToken(QString shortLivedUserToken);
QStringList fetchPageTokens(QString userToken);
The part where I have a bad feeling is the OAuthorizer class. It inevitably includes UI-related code inorder to launch a QML window. Is it a good idea/design?
So I think this design is very much flawed. I would welcome a wholly new, if better design as well as improvements on this one.