QUrl Dailymotion::authUrl() const { QUrl url(QDailymotion::AUTH_URL); #if QT_VERSION >= 0x050000 QUrlQuery query(url); query.addQueryItem("client_id", clientId()); query.addQueryItem("redirect_uri", redirectUri()); query.addQueryItem("response_type", "code"); query.addQueryItem("display", "popup"); QStringList s = scopes(); if (!s.isEmpty()) { query.addQueryItem("scope", s.join("+")); } url.setQuery(query); #else url.addQueryItem("client_id", clientId()); url.addQueryItem("redirect_uri", redirectUri()); url.addQueryItem("response_type", "code"); url.addQueryItem("display", "popup"); QStringList s = scopes(); if (!s.isEmpty()) { url.addQueryItem("scope", s.join("+")); } #endif return url; }
void Dailymotion::setClientId(const QString &id) { if (id != clientId()) { QSettings().setValue("Dailymotion/clientId", id); emit clientIdChanged(); } #ifdef CUTETUBE_DEBUG qDebug() << "Dailymotion::setClientId" << id; #endif }
/*! \brief Requests a device authorization code for the current scopes. This method is used when using the <a target="_blank" href="https://developers.google.com/youtube/v3/guides/authentication#devices">devices flow</a>. After obtaining the authorization code, AuthenticationRequest will emit the authorizationCodeReady() signal and begin polling the server at regular intervals until either the user has granted permission or the authorization code has expired. In either case the finished() signal will be emitted, and the result will either contain a valid access token, or information about any error. The YouTube Data API supports the following scopes: <table> <tr> <th>Scope</th> <th>Description</th> </tr> <tr> <td>https://www.googleapis.com/auth/youtube</td> <td>Manage a YouTube account.</td> </tr> <tr> <td>https://www.googleapis.com/auth/youtube.readonly</td> <td>View a YouTube account.</td> </tr> <tr> <td>https://www.googleapis.com/auth/youtube.upload</td> <td>Upload YouTube videos and manage YouTube videos.</td> </tr> <tr> <td>https://www.googleapis.com/auth/youtubepartner-channel-audit</td> <td>Retrieve the auditDetails part in a channel resource.</td> </tr> </table> */ void AuthenticationRequest::requestAuthorizationCode() { if (status() == Loading) { return; } Q_D(AuthenticationRequest); d->authRequest = AuthenticationRequestPrivate::DeviceCode; setUrl(QUrl(DEVICE_CODE_URL)); setData(QString("scope=" + scopes().join(" ") + "&client_id=" + clientId())); post(); }
void ImgurUploader::upload(const QString &fileName) { QFile *file = new QFile(fileName); if (!file->open(QIODevice::ReadOnly)) { emit error(ImageUploader::FileError, tr("Unable to read screenshot file"), fileName); file->deleteLater(); return; } QNetworkRequest request(QUrl("https://api.imgur.com/3/image")); request.setRawHeader("Authorization", QString("Client-ID %1").arg(clientId()).toLatin1()); QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType); if (!mSettings.value("anonymous", true).toBool()) { request.setRawHeader("Authorization", QByteArray("Bearer ") + mSettings.value("access_token").toByteArray()); if (!mSettings.value("album").toString().isEmpty()) { QHttpPart albumPart; albumPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"album\"")); albumPart.setBody(mSettings.value("album").toByteArray()); multiPart->append(albumPart); } } QHttpPart imagePart; imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QMimeDatabase().mimeTypeForFile(fileName, QMimeDatabase::MatchExtension).name()); imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"image\"")); imagePart.setBodyDevice(file); file->setParent(multiPart); multiPart->append(imagePart); QNetworkReply *reply = Uploader::network()->post(request, multiPart); reply->setProperty("fileName", fileName); this->setProperty("fileName", fileName); multiPart->setParent(reply); #ifdef Q_OS_WIN connect(reply, &QNetworkReply::sslErrors, [reply](const QList<QSslError> &errors) { Q_UNUSED(errors); if (QSysInfo::WindowsVersion <= QSysInfo::WV_2003) { reply->ignoreSslErrors(); } }); #endif connect(reply, &QNetworkReply::uploadProgress, this, &ImgurUploader::uploadProgress); connect(this , &ImgurUploader::cancelRequest, reply, &QNetworkReply::abort); connect(this , &ImgurUploader::cancelRequest, reply, &QNetworkReply::deleteLater); connect(reply, &QNetworkReply::finished, this, &ImgurUploader::finished); }
/*! \brief Submits code in exchange for a YouTube access token. This method is used when authenticating via a web view using the <a target="_blank" href="https://developers.google.com/youtube/v3/guides/authentication#installed-apps">installed applications flow</a>. The code is retrieved from the title of the web page. */ void AuthenticationRequest::exchangeCodeForAccessToken(const QString &code) { if (status() == Loading) { return; } Q_D(AuthenticationRequest); d->authRequest = AuthenticationRequestPrivate::WebToken; setUrl(QUrl(TOKEN_URL)); setData(QString("code=" + code + "&client_id=" + clientId() + "&client_secret=" + clientSecret() + "&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code")); post(); }
void EClientSocket::redirect(const char *host, int port) { // handle redirect if( (m_hostNorm != this->host() || port != this->port())) { if (!m_allowRedirect) { getWrapper()->error(NO_VALID_ID, CONNECT_FAIL.code(), CONNECT_FAIL.msg()); return; } eDisconnect(); eConnectImpl( clientId(), extraAuth(), 0); } }
QString ClientConfiguration::toBackup(QString const& password) const { QByteArray encryptionKey(BACKUP_ENCRYPTION_KEY_BYTES, 0x00); // Generate a Salt QByteArray salt(BACKUP_SALT_BYTES, 0x00); randombytes_buf(salt.data(), BACKUP_SALT_BYTES); // Convert the password into bytes QByteArray password8Bit = password.toUtf8(); // Generate the encryption key for the Backup from the Salt and the Password PKCS5_PBKDF2_HMAC(reinterpret_cast<unsigned char*>(password8Bit.data()), password8Bit.size(), reinterpret_cast<unsigned char*>(salt.data()), BACKUP_SALT_BYTES, BACKUP_KEY_PBKDF_ITERATIONS, BACKUP_ENCRYPTION_KEY_BYTES, reinterpret_cast<unsigned char*>(encryptionKey.data())); QByteArray nonceBytes(crypto_stream_NONCEBYTES, 0x00); // The backup content QByteArray clientId(IdentityHelper::uint64ToIdentityString(getClientIdentity().getContactId()).toLatin1()); if (clientId.size() != BACKUP_IDENTITY_BYTES) { throw InternalErrorException() << QString("Could not build backup - invalid client identity length (%1 vs. %2 Bytes).").arg(clientId.size()).arg(BACKUP_IDENTITY_BYTES).toStdString(); } QByteArray clientSecKey(getClientLongTermKeyPair().getPrivateKey()); if (clientSecKey.size() != PROTO_KEY_LENGTH_BYTES) { throw InternalErrorException() << QString("Could not build backup - invalid client secret key length (%1 vs. %2 Bytes).").arg(clientSecKey.size()).arg(PROTO_KEY_LENGTH_BYTES).toStdString(); } QByteArray backup(salt); backup.append(clientId); backup.append(clientSecKey); // Compute Hash QByteArray controlHash(crypto_hash_sha256_BYTES, 0x00); crypto_hash_sha256(reinterpret_cast<unsigned char*>(controlHash.data()), reinterpret_cast<unsigned char*>(backup.data() + BACKUP_SALT_BYTES), BACKUP_IDENTITY_BYTES + PROTO_KEY_LENGTH_BYTES); backup.append(controlHash.left(BACKUP_HASH_BYTES)); if (backup.size() != (BACKUP_SALT_BYTES + BACKUP_IDENTITY_BYTES + PROTO_KEY_LENGTH_BYTES + BACKUP_HASH_BYTES)) { throw InternalErrorException() << QString("Could not build backup - invalid packet length (%1 vs. %2 Bytes).").arg(clientSecKey.size()).arg(BACKUP_SALT_BYTES + BACKUP_IDENTITY_BYTES + PROTO_KEY_LENGTH_BYTES + BACKUP_HASH_BYTES).toStdString(); } // The Backup is build from SALT + IDENTITY + KEY + HASH crypto_stream_xor(reinterpret_cast<unsigned char*>(backup.data() + BACKUP_SALT_BYTES), reinterpret_cast<unsigned char*>(backup.data() + BACKUP_SALT_BYTES), BACKUP_IDENTITY_BYTES + PROTO_KEY_LENGTH_BYTES + BACKUP_HASH_BYTES, reinterpret_cast<unsigned char*>(nonceBytes.data()), reinterpret_cast<unsigned char*>(encryptionKey.data())); // Encode in Base32 return Base32::encodeBase32Sequence(backup); }
void OAuth::getNewAccessToken() { // if two request refresh key at the same time only one request to be sent if (isRunning()) return; netManager = new QNetworkAccessManager(); if (!netManager) { qDebug() << "Unable to create QNetworkAccessManager!"; //emit complete("Unable to create QNetworkAccessManager!", false); return; } QUrl url(m_refresh_url); //https://api.imgur.com/oauth2/token?client_id=2137fbd8fcb4a0a&client_secret=ffc769f3b79ac245e4d8871518d9617ceaf4b2cd&refresh_token=f1ae5cc3f2f231a29db009a54c5c5bb3ebc20684&grant_type=refresh_token QNetworkRequest req(url); req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); QUrl postData; postData.addQueryItem(OAUTH_CLIENT_ID, clientId().toAscii()); postData.addQueryItem(OAUTH_CLIENT_SECRET, clientSecret().toAscii()); // If redirect is required and available if (!m_redirect_uri.isEmpty()) postData.addQueryItem(OAUTH_REDIRECT_URI, redirectURI().toAscii()); if (m_response_type == TOKEN) { postData.addQueryItem(OAUTH_REFRESH_TOKEN, refreshToken().toAscii()); postData.addQueryItem(OAUTH_GRANT_TYPE, OAUTH_REFRESH_TOKEN); } else { postData.addQueryItem(OAUTH_CODE, code().toAscii()); postData.addQueryItem(OAUTH_GRANT_TYPE, OAUTH_AUTHORIZATION_CODE); } QNetworkReply* ipReply = netManager->post(req, postData.encodedQuery()); bool connectResult; Q_UNUSED(connectResult); connectResult = connect(netManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(onNewAccessTokenReply(QNetworkReply*))); Q_ASSERT(connectResult); m_running = true; }
bool CHostIce::registerClient( const ::Client::CClientPrx & client, const std::string & nickname, std::string & idOrErrMsg, const ::Ice::Current & c ) { IceUtil::Mutex::Lock lock( m_mut ); QLOG_TRACE() << "registerClient( " << QString::fromUtf8( nickname.data(), nickname.size() ) << " )"; try { //client->cam( c.ctx ); //client->ice_id( c.ctx ); if ( !nicknameUnique( nickname ) ) { std::ostringstream msg; msg << "ERROR: \"" << nickname << "\" is aready in use"; QLOG_TRACE() << QString::fromUtf8( msg.str().data(), msg.str().size() ); idOrErrMsg = msg.str(); return false; } std::string id = clientId( nickname, client ); if ( hasClient( id ) ) { std::ostringstream msg; msg << "ERROR: your client id is \"" << id << "\", it is aready in use. Failed to add client."; QLOG_TRACE() << QString::fromUtf8( msg.str().data(), msg.str().size() ); idOrErrMsg = msg.str(); return false; } QLOG_TRACE() << "Assigned id: " << QString::fromStdString( id ); CClientDesc cd( nickname, client ); idOrErrMsg = id; addClient( id, cd ); validateClientList( c ); sendClientList( c ); return true; } catch( const Ice::Exception & ex ) { QLOG_TRACE() << "Exception: " << ex.toString().c_str(); idOrErrMsg = ex.toString().c_str(); fprintf(stderr, "%s\n", ex.toString().c_str()); } return false; }
void ImgurUploader::refreshAuthorization(const QString &refresh_token, AuthorizationCallback callback) { if (refresh_token.isEmpty()) { callback(false); return; } QByteArray parameters; parameters.append(QString("refresh_token=").toUtf8()); parameters.append(QUrl::toPercentEncoding(refresh_token)); parameters.append(QString("&client_id=").toUtf8()); parameters.append(QUrl::toPercentEncoding(clientId())); parameters.append(QString("&client_secret=").toUtf8()); parameters.append(QUrl::toPercentEncoding(clientSecret())); parameters.append(QString("&grant_type=refresh_token").toUtf8()); QNetworkRequest request(QUrl("https://api.imgur.com/oauth2/token")); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); QNetworkReply *reply = Uploader::network()->post(request, parameters); authorizationReply(reply, callback); }
/*! \fn bool FacebookConnection::authenticate() Authenticates user with Facebook. User is authenticated if Facebook \l {FacebookConnection::accessToken}{access token} is valid. User can also make requests to publically available Facebook data without authentication. Returns true if the operation was successfully started and there will be a authenticateCompleted() signal emitted later; otherwise returns false. */ bool FacebookConnection::authenticate() { bool ret = m_facebook->isAuthorized(); if (!busy() && !ret) { m_apiCall = Authenticate; WebInterface *webInterface = qobject_cast<WebInterface*>(SocialConnection::webInterface()); if (webInterface) { webInterface->setActive(true); setBusy(true); setAccessToken(""); setAuthenticated(false); QString url = QString(UrlAuthenticationFormat).arg(OAuthUrlStr) .arg(clientId()).arg(SuccessUrlStr); // Add permissions to the authorization URL if (m_permissions.count() > 0) { url += "&scope="; url += m_permissions.join(","); } webInterface->setUrl(url); ret = true; } } else if (ret){ setAuthenticated(true); QMetaObject::invokeMethod(this, "authenticateCompleted", Qt::QueuedConnection, Q_ARG(bool, true)); } return ret; }