QString OAuthPrivate::buildAuthHeader(const QString & method, const QString & url, const Params & data, const QString & verifier)
{
    QMap<QString, QString> params;

    params.insert("oauth_consumer_key", consumerKey.toAscii());
    params.insert("oauth_nonce", Helper::identifier(42));
    params.insert("oauth_signature_method", "HMAC-SHA1");
    params.insert("oauth_timestamp", QString("%1").arg(Helper::timestamp()));
    params.insert("oauth_version", "1.0");

    if(!verifier.isEmpty())
        params.insert("oauth_verifier", verifier);

    if(!oauthToken.isEmpty())
        params.insert("oauth_token", oauthToken.toAscii());

    params.unite(data);

    QString authStr;
    Params::const_iterator i = params.constBegin();

    params.insert("oauth_signature", signature(signingKey(consumerSecret, oauthTokenSecret), baseString(method, url, paramsString(params))));

    while (i != params.constEnd()){
        authStr += QUrl::toPercentEncoding(i.key()) + "=\"" + QUrl::toPercentEncoding(i.value()) + "\", ";
        ++i;
    }

    return authStr.mid(0, authStr.length() - 2);
}
示例#2
0
/// param management -- not threadsafe
const QVariant & DataFile::getParam(const QString & name) const
{
    Params::const_iterator it = params.find(name);
    if (it != params.end()) return it.value();
    static QVariant invalid;
    return invalid;
}
QString OAuthPrivate::paramsString(const Params &params){

    QString paramStr;
    Params::const_iterator i = params.constBegin();
    while (i != params.constEnd()){
        paramStr += QUrl::toPercentEncoding(i.key()) + "=" + QUrl::toPercentEncoding(i.value()) + "&";
        ++i;
    }
    return paramStr.mid(0, paramStr.length() - 1);
}