class QOAuth1Signature

Implements OAuth 1 signature methods. More

Synopsis

Methods

Static functions

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

Detailed Description

OAuth-authenticated requests can have two sets of credentials: those passed via the “oauth_consumer_key” parameter and those in the “oauth_token” parameter. In order for the server to verify the authenticity of the request and prevent unauthorized access, the client needs to prove that it is the rightful owner of the credentials. This is accomplished using the shared-secret (or RSA key) part of each set of credentials.

OAuth specifies three methods for the client to establish its rightful ownership of the credentials: “HMAC-SHA1”, “RSA-SHA1”, and “PLAINTEXT”. Each generates a “signature” with which the request is “signed”; the first two use a digest of the data signed in generating this, though the last does not. The “RSA-SHA1” method is not supported here; it would use an RSA key rather than the shared-secret associated with the client credentials.

class HttpRequestMethod

Indicates the HTTP request method.

Constant

Description

QOAuth1Signature.HttpRequestMethod.Head

HEAD method.

QOAuth1Signature.HttpRequestMethod.Get

GET method.

QOAuth1Signature.HttpRequestMethod.Put

PUT method.

QOAuth1Signature.HttpRequestMethod.Post

POST method.

QOAuth1Signature.HttpRequestMethod.Delete

DELETE method.

QOAuth1Signature.HttpRequestMethod.Custom

Identifies a custom method.

QOAuth1Signature.HttpRequestMethod.Unknown

Method not set.

__init__(other)
Parameters:

otherQOAuth1Signature

Creates a copy of other.

__init__([url=QUrl()[, method=QOAuth1Signature.HttpRequestMethod.Post[, parameters={}]]])
Parameters:

Creates a QOAuth1Signature using

  • url as the target address

  • method as the HTTP method used to send the request

  • and the given user parameters to augment the request.

__init__(url, clientSharedKey, tokenSecret[, method=QOAuth1Signature.HttpRequestMethod.Post[, parameters={}]])
Parameters:
  • urlQUrl

  • clientSharedKey – str

  • tokenSecret – str

  • methodHttpRequestMethod

  • parameters – .QMultiMapQString,QVariant

Creates a QOAuth1Signature using

  • url as the target address

  • clientSharedKey as the user token used to verify the signature

  • tokenSecret as the negotiated token used to verify the signature

  • method as the HTTP method used to send the request

  • and the given user parameters to augment the request.

addRequestBody(body)
Parameters:

bodyQUrlQuery

Adds the request body to the signature. When a POST request body contains arguments they should be included in the signed data.

clientSharedKey()
Return type:

str

Returns the user secret used to generate the signature.

customMethodString()
Return type:

QByteArray

Returns the custom method string.

hmacSha1()
Return type:

QByteArray

Generates the HMAC-SHA1 signature using the client shared secret and, where available, token secret.

httpRequestMethod()
Return type:

HttpRequestMethod

Returns the request method.

insert(key, value)
Parameters:
  • key – str

  • value – object

Inserts a new pair key, value into the signature. When a POST request body contains arguments they should be included in the signed data.

keys()
Return type:

.list of QString

Retrieves the list of keys of parameters included in the signed data.

parameters()
Return type:

.QMultiMapQString,QVariant

Returns the parameters.

See also

setParameters()

plainText()
Return type:

QByteArray

Generates the PLAINTEXT signature.

static plainText(clientSharedSecret, tokenSecret)
Parameters:
  • clientSharedSecret – str

  • tokenSecret – str

Return type:

QByteArray

Generates a PLAINTEXT signature from the client secret clientSharedKey and the token secret tokenSecret.

rsaSha1()
Return type:

QByteArray

Generates the RSA-SHA1 signature.

Note

Currently this method is not supported.

setClientSharedKey(secret)
Parameters:

secret – str

Sets secret as the user secret used to generate the signature.

setCustomMethodString(verb)
Parameters:

verbQByteArray

Sets a custom request method. Will set the httpRequestMethod to Custom and store the verb to use it for the generation of the signature.

Note

Using this method is required when working with custom verbs. Setting only the request method will fail, as the signure needs to know the actual verb.

setHttpRequestMethod(method)
Parameters:

methodHttpRequestMethod

Sets the request method.

setParameters(parameters)
Parameters:

parameters – .QMultiMapQString,QVariant

Sets the parameters.

See also

parameters()

setTokenSecret(secret)
Parameters:

secret – str

Sets secret as the negotiated secret used to generate the signature.

See also

tokenSecret()

setUrl(url)
Parameters:

urlQUrl

Sets the URL to url.

See also

url()

swap(other)
Parameters:

otherQOAuth1Signature

Swaps signature other with this signature. This operation is very fast and never fails.

take(key)
Parameters:

key – str

Return type:

object

Removes key and any associated value from the signed data.

tokenSecret()
Return type:

str

Returns the negotiated secret used to generate the signature.

See also

setTokenSecret()

url()
Return type:

QUrl

Returns the URL.

See also

setUrl()

value(key[, defaultValue=None])
Parameters:
  • key – str

  • defaultValue – object

Return type:

object

Returns the value associated with key, if present in the signed data, otherwise defaultValue.