void TwitterInterface::GetAccess () { #ifdef WP_DEBUG qDebug() << Q_FUNC_INFO; #endif connect (OAuthManager_, SIGNAL (temporaryTokenReceived (QString, QString)), this, SLOT (onTemporaryTokenReceived (QString, QString))); connect (OAuthManager_, SIGNAL (authorizationReceived (QString, QString)), this, SLOT (onAuthorizationReceived (QString, QString))); connect (OAuthManager_, SIGNAL (accessTokenReceived (QString, QString)), this, SLOT (onAccessTokenReceived (QString, QString))); connect (OAuthManager_, SIGNAL (authorizationPageRequested (QUrl)), this, SLOT (onAuthorizationPageRequested (QUrl))); OAuthRequest_->initRequest (KQOAuthRequest::TemporaryCredentials, QUrl ("https://api.twitter.com/oauth/request_token")); OAuthRequest_->setConsumerKey (ConsumerKey_); OAuthRequest_->setConsumerSecretKey (ConsumerKeySecret_); OAuthManager_->setHandleUserAuthorization (true); OAuthManager_->setHandleAuthorizationPageOpening (false); OAuthManager_->executeRequest (OAuthRequest_); }
OAuthDialog::OAuthDialog(Context *context, OAuthSite site) : context(context), site(site) { setAttribute(Qt::WA_DeleteOnClose); setWindowTitle(tr("OAuth")); // check if SSL is available - if not - message and end if (!QSslSocket::supportsSsl()) { QString text = QString(tr("SSL Security Libraries required for 'Authorise' are missing in this installation.")); QMessageBox sslMissing(QMessageBox::Critical, tr("Authorization Error"), text); sslMissing.exec(); noSSLlib = true; return; } // SSL is available - so authorisation can take place noSSLlib = false; layout = new QVBoxLayout(); layout->setSpacing(0); layout->setContentsMargins(2,0,2,2); setLayout(layout); #if QT_VERSION < 0x050000 || !defined(Q_OS_MAC) view = new QWebView(); #else view = new QWebEngineView(); #endif view->setContentsMargins(0,0,0,0); view->page()->view()->setContentsMargins(0,0,0,0); view->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); view->setAcceptDrops(false); layout->addWidget(view); QString urlstr = ""; if (site == STRAVA) { urlstr = QString("https://www.strava.com/oauth/authorize?"); urlstr.append("client_id=").append(GC_STRAVA_CLIENT_ID).append("&"); urlstr.append("scope=view_private,write&"); urlstr.append("redirect_uri=http://www.goldencheetah.org/&"); urlstr.append("response_type=code&"); urlstr.append("approval_prompt=force"); } else if (site == DROPBOX) { urlstr = QString("https://www.dropbox.com/1/oauth2/authorize?"); #ifdef GC_DROPBOX_CLIENT_ID urlstr.append("client_id=").append(GC_DROPBOX_CLIENT_ID).append("&"); #endif urlstr.append("redirect_uri=https://goldencheetah.github.io/blank.html&"); urlstr.append("response_type=code&"); urlstr.append("force_reapprove=true"); } else if (site == TWITTER) { #ifdef GC_HAVE_KQOAUTH oauthRequest = new KQOAuthRequest; oauthManager = new KQOAuthManager(this); connect(oauthManager, SIGNAL(temporaryTokenReceived(QString,QString)), this, SLOT(onTemporaryTokenReceived(QString, QString))); connect(oauthManager, SIGNAL(authorizationReceived(QString,QString)), this, SLOT( onAuthorizationReceived(QString, QString))); connect(oauthManager, SIGNAL(accessTokenReceived(QString,QString)), this, SLOT(onAccessTokenReceived(QString,QString))); connect(oauthManager, SIGNAL(requestReady(QByteArray)), this, SLOT(onRequestReady(QByteArray))); connect(oauthManager, SIGNAL(authorizationPageRequested(QUrl)), this, SLOT(onAuthorizationPageRequested(QUrl))); oauthRequest->initRequest(KQOAuthRequest::TemporaryCredentials, QUrl("https://api.twitter.com/oauth/request_token")); oauthRequest->setConsumerKey(GC_TWITTER_CONSUMER_KEY); oauthRequest->setConsumerSecretKey(GC_TWITTER_CONSUMER_SECRET); oauthManager->setHandleUserAuthorization(true); oauthManager->setHandleAuthorizationPageOpening(false); oauthManager->executeRequest(oauthRequest); #endif } else if (site == CYCLING_ANALYTICS) { urlstr = QString("https://www.cyclinganalytics.com/api/auth?"); urlstr.append("client_id=").append(GC_CYCLINGANALYTICS_CLIENT_ID).append("&"); urlstr.append("scope=modify_rides&"); urlstr.append("redirect_uri=http://www.goldencheetah.org/&"); urlstr.append("response_type=code&"); urlstr.append("approval_prompt=force"); } else if (site == GOOGLE_CALENDAR) { // OAUTH 2.0 - Google flow for installed applications urlstr = QString("https://accounts.google.com/o/oauth2/auth?"); urlstr.append("scope=https://www.googleapis.com/auth/calendar&"); urlstr.append("redirect_uri=urn:ietf:wg:oauth:2.0:oob&"); urlstr.append("response_type=code&"); urlstr.append("client_id=").append(GC_GOOGLE_CALENDAR_CLIENT_ID); } // different process to get the token for STRAVA, CYCLINGANALYTICS vs. TWITTER if (site == DROPBOX || site == STRAVA || site == CYCLING_ANALYTICS || site == GOOGLE_CALENDAR ) { url = QUrl(urlstr); view->setUrl(url); // connects connect(view, SIGNAL(urlChanged(const QUrl&)), this, SLOT(urlChanged(const QUrl&))); connect(view, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished(bool))); }