3
,[A\
@ s$ d Z ddlmZmZ ddlZddlZddlZddlZddlm Z m
Z
mZmZm
Z
ddlmZ yddlZW n ek
r ddljZY nX ejeZdd Zd(d d
Zdg ddd
fddZdd Zdd Zdd Zdadd Zdd Zdd Z dd Z!dd Z"d)d d!Z#d"d# Z$d$d% Z%d*d&d'Z&dS )+a
oauthlib.oauth1.rfc5849.signature
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This module represents a direct implementation of `section 3.4`_ of the spec.
Terminology:
* Client: software interfacing with an OAuth API
* Server: the API provider
* Resource Owner: the user who is granting authorization to the client
Steps for signing a request:
1. Collect parameters from the uri query, auth header, & body
2. Normalize those parameters
3. Normalize the uri
4. Pass the normalized uri, normalized parameters, and http method to
construct the base string
5. Pass the base string and any keys needed to a signing function
.. _`section 3.4`: https://tools.ietf.org/html/rfc5849#section-3.4
)absolute_importunicode_literalsN)
bytes_typeextract_paramssafe_string_equalsunicode_type urldecode )utilsc C s> t j| j }|d7 }|t j|7 }|d7 }|t j|7 }|S )aY **String Construction**
Per `section 3.4.1.1`_ of the spec.
For example, the HTTP request::
POST /request?b5=%3D%253D&a3=a&c%40=&a2=r%20b HTTP/1.1
Host: example.com
Content-Type: application/x-www-form-urlencoded
Authorization: OAuth realm="Example",
oauth_consumer_key="9djdj82h48djs9d2",
oauth_token="kkk9d7dh3k39sjv7",
oauth_signature_method="HMAC-SHA1",
oauth_timestamp="137131201",
oauth_nonce="7d8f3e4a",
oauth_signature="bYT5CMsGcbgUdFHObYMEfcx6bsw%3D"
c2&a3=2+q
is represented by the following signature base string (line breaks
are for display purposes only)::
POST&http%3A%2F%2Fexample.com%2Frequest&a2%3Dr%2520b%26a3%3D2%2520q
%26a3%3Da%26b5%3D%253D%25253D%26c%2540%3D%26c2%3D%26oauth_consumer_
key%3D9djdj82h48djs9d2%26oauth_nonce%3D7d8f3e4a%26oauth_signature_m
ethod%3DHMAC-SHA1%26oauth_timestamp%3D137131201%26oauth_token%3Dkkk
9d7dh3k39sjv7
.. _`section 3.4.1.1`: https://tools.ietf.org/html/rfc5849#section-3.4.1.1
&)r
escapeupper)http_methodZbase_string_uriZ%normalized_encoded_request_parametersbase_string r /usr/lib/python3.6/signature.pyconstruct_base_string+ s (r c
C s t | tstdtj| \}}}}}}| s4| r