def test_bearer_body(): client = Client("A") client.client_secret = "boarding pass" request_args = {"access_token": "Sesame"} cis = ResourceRequest() http_args = oauth2.bearer_body(client, cis, request_args) assert cis["access_token"] == "Sesame" print http_args assert http_args is None # ---------- resp = AuthorizationResponse(code="code", state="state") grant = Grant() grant.add_code(resp) atr = AccessTokenResponse( access_token="2YotnFZFEjr1zCsicMWpAA", token_type="example", refresh_token="tGzv3JOkF0XG5Qx2TlKWIA", example_parameter="example_value", scope=["inner", "outer"], ) grant.add_token(atr) client.grant["state"] = grant cis = ResourceRequest() http_args = oauth2.bearer_body(client, cis, {}, state="state", scope="inner") assert cis["access_token"] == "2YotnFZFEjr1zCsicMWpAA" print http_args assert http_args is None
def test_bearer_body_get_token(): client = Client("A") client.client_secret = "boarding pass" client.state = "state" resp1 = AuthorizationResponse(code="auth_grant", state="state") client.parse_response(AuthorizationResponse, resp1.to_urlencoded(), "urlencoded") resp2 = AccessTokenResponse(access_token="token1", token_type="Bearer", expires_in=0, state="state") client.parse_response(AccessTokenResponse, resp2.to_urlencoded(), "urlencoded") cis = ResourceRequest() oauth2.bearer_body(client, cis) assert "access_token" in cis assert cis["access_token"] == "token1"