Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
facebook.py28 linesDownload Raw Back to compliance_fixes
1from json import dumps2from urllib.parse import parse_qsl3 4 5def facebook_compliance_fix(session):6    def _compliance_fix(r):7        # if Facebook claims to be sending us json, let's trust them.8        if "application/json" in r.headers.get("content-type", {}):9            return r10 11        # Facebook returns a content-type of text/plain when sending their12        # x-www-form-urlencoded responses, along with a 200. If not, let's13        # assume we're getting JSON and bail on the fix.14        if "text/plain" in r.headers.get("content-type", {}) and r.status_code == 200:15            token = dict(parse_qsl(r.text, keep_blank_values=True))16        else:17            return r18 19        expires = token.get("expires")20        if expires is not None:21            token["expires_in"] = expires22        token["token_type"] = "Bearer"23        r._content = dumps(token).encode()24        return r25 26    session.register_compliance_hook("access_token_response", _compliance_fix)27    return session28 
codekingpro/portable-devtools · Team Ai