| 25 | |
| 26 | |
| 27 | class OAuth1Session(OAuth1Client, Session): |
| 28 | auth_class = OAuth1Auth |
| 29 | |
| 30 | def __init__( |
| 31 | self, |
| 32 | client_id, |
| 33 | client_secret=None, |
| 34 | token=None, |
| 35 | token_secret=None, |
| 36 | redirect_uri=None, |
| 37 | rsa_key=None, |
| 38 | verifier=None, |
| 39 | signature_method=SIGNATURE_HMAC_SHA1, |
| 40 | signature_type=SIGNATURE_TYPE_HEADER, |
| 41 | force_include_body=False, |
| 42 | **kwargs, |
| 43 | ): |
| 44 | Session.__init__(self) |
| 45 | update_session_configure(self, kwargs) |
| 46 | OAuth1Client.__init__( |
| 47 | self, |
| 48 | session=self, |
| 49 | client_id=client_id, |
| 50 | client_secret=client_secret, |
| 51 | token=token, |
| 52 | token_secret=token_secret, |
| 53 | redirect_uri=redirect_uri, |
| 54 | rsa_key=rsa_key, |
| 55 | verifier=verifier, |
| 56 | signature_method=signature_method, |
| 57 | signature_type=signature_type, |
| 58 | force_include_body=force_include_body, |
| 59 | **kwargs, |
| 60 | ) |
| 61 | |
| 62 | def rebuild_auth(self, prepared_request, response): |
| 63 | """When being redirected we should always strip Authorization |
| 64 | header, since nonce may not be reused as per OAuth spec. |
| 65 | """ |
| 66 | if "Authorization" in prepared_request.headers: |
| 67 | # If we get redirected to a new host, we should strip out |
| 68 | # any authentication headers. |
| 69 | prepared_request.headers.pop("Authorization", True) |
| 70 | prepared_request.prepare_auth(self.auth) |
| 71 | |
| 72 | @staticmethod |
| 73 | def handle_error(error_type, error_description): |
| 74 | raise OAuthError(error_type, error_description) |
no outgoing calls