This package provides filters for eliding sensitive data in HTTP transactions with Facebook recorded with VCR.py.
Install from PyPI:
pip install vcrpy-facebook
Instantiate VCR with kwargs provided by vcrpy-facebook
:
import vcr
import vcr_facebook
kwargs = vcr_facebook.get_vcr_kwargs()
my_vcr = vcr.VCR(**kwargs)
If you already have kwargs, then you can pass them in the call to
get_vcr_kwargs
and they'll be preserved:
kwargs = dict(
filter_headers=['authorization'],
match_on=['method', 'uri', 'headers', 'raw_body'],
)
kwargs = vcr_facebook.get_vcr_kwargs(kwargs)
my_vcr = vcr.VCR(**kwargs)
If you're using vcrpy-unittest then it works like this:
import vcr_unittest
import vcr_facebook
class MyTestCase(vcr_unittest.VCRTestCase):
def _get_vcr_kwargs(self, **kwargs):
kwargs = super(MyTestCase, self)._get_vcr_kwargs(**kwargs)
kwargs = vcr_facebook.get_vcr_kwargs(kwargs)
return kwargs
You can pass some extra kwargs to get_vcr_kwargs
to customize the behavior
of vcrpy-facebook
.
By default vcrpy-facebook
replaces tokens with a string like
XXX-d41d8cd98f00b204e9800998ecf8427e
where the right side is the md5 hex
digest of the elided token.
Pass a callable as elide_access_token
to customize how Facebook access
tokens are elided, for example to look up a username from django-allauth:
def elide_access_token(token):
try:
user = User.objects.get(socialaccount__socialtoken__token=token)
except User.DoesNotExist:
pass
else:
return 'USER-{}'.format(user.username)
By default vcrpy-facebook
replaces appsecret_proof with a string like
XXX-d41d8cd98f00b204e9800998ecf8427e
where the right side is the md5 hex
digest of the elided proof.
Pass a callable as elide_appsecret_proof
to customize how the proof is
elided. The callable should take two positional parameters: proof
and
token
(since the proof is a signature based on the token used for the
transaction).
This is only really useful for an application with multiple Facebook apps, and wanting to make sure the proofs are generated with an app that corresponds to the token.
vcrpy-facebook
supports the same Python versions supported by VCR.py.
This library uses the MIT license, which is the same as VCR.py. See LICENSE.txt for more details.