PySide6.QtNetworkAuth.QOAuth1Signature¶
- class QOAuth1Signature¶
实现OAuth 1签名方法。更多…
概要¶
方法¶
def
__init__()def
addRequestBody()def
hmacSha1()def
insert()def
keys()def
parameters()def
plainText()def
rsaSha1()def
setParameters()def
setTokenSecret()def
setUrl()def
swap()def
take()def
tokenSecret()def
url()def
value()
静态函数¶
def
plainText()
注意
本文档可能包含从C++自动翻译到Python的代码片段。我们始终欢迎对代码片段翻译的贡献。如果您发现翻译问题,您也可以通过在我们的https:/bugreports.qt.io/projects/PYSIDE上创建工单来告知我们。
详细描述¶
OAuth认证的请求可以有两组凭证:通过“oauth_consumer_key”参数传递的凭证和“oauth_token”参数中的凭证。为了让服务器验证请求的真实性并防止未经授权的访问,客户端需要证明它是凭证的合法所有者。这是通过使用每组凭证的共享密钥(或RSA密钥)部分来实现的。
OAuth 指定了三种方法供客户端建立其对凭据的合法所有权:“HMAC-SHA1”、“RSA-SHA1”和“PLAINTEXT”。每种方法都会生成一个“签名”,用于“签署”请求;前两种方法在生成签名时使用了数据的摘要,而最后一种则没有。这里不支持“RSA-SHA1”方法;它将使用RSA密钥,而不是与客户端凭据关联的共享密钥。
- class HttpRequestMethod¶
指示HTTP请求方法。
常量
描述
QOAuth1Signature.HttpRequestMethod.Head
HEAD 方法。
QOAuth1Signature.HttpRequestMethod.Get
GET 方法。
QOAuth1Signature.HttpRequestMethod.Put
PUT 方法。
QOAuth1Signature.HttpRequestMethod.Post
POST 方法。
QOAuth1Signature.HttpRequestMethod.Delete
DELETE 方法。
QOAuth1Signature.HttpRequestMethod.Custom
标识一个自定义方法。
QOAuth1Signature.HttpRequestMethod.Unknown
方法未设置。
- __init__(other)¶
- Parameters:
其他 –
QOAuth1Signature
创建
other的副本。- __init__([url=QUrl()[, method=QOAuth1Signature.HttpRequestMethod.Post[, parameters={}]]])
- Parameters:
url –
QUrlmethod –
HttpRequestMethodparameters – .QMultiMapQString,QVariant
创建一个
QOAuth1Signature使用url作为目标地址method作为用于发送请求的HTTP方法并使用给定的用户
parameters来增强请求。
- __init__(url, clientSharedKey, tokenSecret[, method=QOAuth1Signature.HttpRequestMethod.Post[, parameters={}]])
- Parameters:
url –
QUrlclientSharedKey – str
tokenSecret – str
method –
HttpRequestMethodparameters – .QMultiMapQString,QVariant
使用
QOAuth1Signature创建url作为目标地址clientSharedKey作为用于验证签名的用户令牌tokenSecret作为用于验证签名的协商令牌method作为用于发送请求的HTTP方法并使用给定的用户
parameters来增强请求。
将请求
body添加到签名中。当POST请求体包含参数时,它们应包含在签名数据中。- Return type:
字符串
返回用于生成签名的用户密钥。
另请参阅
- customMethodString()¶
- Return type:
返回自定义方法字符串。
- hmacSha1()¶
- Return type:
使用客户端共享密钥和(如果可用)令牌密钥生成HMAC-SHA1签名。
- httpRequestMethod()¶
- Return type:
返回请求方法。
- insert(key, value)¶
- Parameters:
key – str
value – 对象
将一个新的键值对
key,value插入到签名中。当POST请求体包含参数时,这些参数应包含在签名数据中。- keys()¶
- Return type:
.QString 列表
检索包含在签名数据中的参数键列表。
- parameters()¶
- Return type:
.QMultiMapQString, QVariant
返回参数。
另请参阅
- plainText()¶
- Return type:
生成PLAINTEXT签名。
- static plainText(clientSharedSecret, tokenSecret)
- Parameters:
clientSharedSecret – str
tokenSecret – str
- Return type:
从客户端密钥
clientSharedKey和令牌密钥tokenSecret生成一个 PLAINTEXT 签名。- rsaSha1()¶
- Return type:
生成RSA-SHA1签名。
注意
目前不支持此方法。
- Parameters:
secret – str
将
secret设置为用于生成签名的用户密钥。另请参阅
- setCustomMethodString(verb)¶
- Parameters:
动词 –
QByteArray
设置自定义请求方法。将设置
httpRequestMethod为Custom并存储verb以用于签名的生成。注意
在使用自定义动词时,需要使用此方法。仅设置请求方法将失败,因为签名需要知道实际的动词。
- setHttpRequestMethod(method)¶
- Parameters:
方法 –
HttpRequestMethod
设置请求
method。另请参阅
- setParameters(parameters)¶
- Parameters:
参数 – .QMultiMapQString,QVariant
设置
parameters。另请参阅
- setTokenSecret(secret)¶
- Parameters:
secret – str
将
secret设置为用于生成签名的协商密钥。另请参阅
将URL设置为
url。另请参阅
- swap(other)¶
- Parameters:
其他 –
QOAuth1Signature
将此签名与
other签名交换。此操作非常快速且永远不会失败。- take(key)¶
- Parameters:
key – str
- Return type:
对象
从签名数据中移除
key和任何关联的值。- tokenSecret()¶
- Return type:
字符串
返回用于生成签名的协商密钥。
另请参阅
返回URL。
另请参阅
- value(key[, defaultValue=None])¶
- Parameters:
key – str
defaultValue – 对象
- Return type:
对象
返回与
key关联的值,如果存在于签名数据中,否则返回defaultValue。