示例#1
0
void OAuthenticator::StartAuthorisation(const QString& oauth_endpoint,
                                        const QString& token_endpoint,
                                        const QString& scope) {
  token_endpoint_ = QUrl(token_endpoint);
  LocalRedirectServer* server = new LocalRedirectServer(this);
  server->Listen();

  QUrl url = QUrl(oauth_endpoint);
  url.addQueryItem("response_type", "code");
  url.addQueryItem("client_id", client_id_);
  QUrl redirect_url;

  const QString port = QString::number(server->url().port());

  if (redirect_style_ == RedirectStyle::REMOTE) {
    redirect_url = QUrl(kRemoteURL);
    redirect_url.addQueryItem("port", port);
  } else if (redirect_style_ == RedirectStyle::REMOTE_WITH_STATE) {
    redirect_url = QUrl(kRemoteURL);
    url.addQueryItem("state", port);
  } else {
    redirect_url = server->url();
  }

  url.addQueryItem("redirect_uri", redirect_url.toString());
  url.addQueryItem("scope", scope);

  NewClosure(server, SIGNAL(Finished()), this, &OAuthenticator::RedirectArrived,
             server, redirect_url);

  QDesktopServices::openUrl(url);
}
示例#2
0
void DropboxAuthenticator::Authorise() {
  LocalRedirectServer* server = new LocalRedirectServer(this);
  server->Listen();

  NewClosure(server, SIGNAL(Finished()), this,
             SLOT(RedirectArrived(LocalRedirectServer*)), server);

  QUrl url(kAuthoriseEndpoint);
  url.addQueryItem("oauth_token", token_);
  url.addQueryItem("oauth_callback", server->url().toString());

  QDesktopServices::openUrl(url);
}
示例#3
0
void LastFMService::Authenticate() {
  QUrl url("https://www.last.fm/api/auth/");
  url.addQueryItem("api_key", kApiKey);

  LocalRedirectServer* server = new LocalRedirectServer(this);
  server->Listen();

  url.addQueryItem("cb", server->url().toString());

  NewClosure(server, SIGNAL(Finished()), [this, server]() {
    server->deleteLater();

    const QUrl& url = server->request_url();
    QString token = url.queryItemValue("token");

    QUrl session_url("https://ws.audioscrobbler.com/2.0/");
    session_url.addQueryItem("api_key", kApiKey);
    session_url.addQueryItem("method", "auth.getSession");
    session_url.addQueryItem("token", token);
    session_url.addQueryItem("api_sig", SignApiRequest(session_url.queryItems()));

    QNetworkReply* reply = network_->get(QNetworkRequest(session_url));
    NewClosure(reply, SIGNAL(finished()), this, SLOT(AuthenticateReplyFinished(QNetworkReply*)), reply);
  });