Ejemplo n.º 1
0
def test_bearer_header_with_http_args():
    client = Client("A")
    client.client_secret = "boarding pass"

    request_args = {"access_token": "Sesame"}

    cis = ResourceRequest()

    http_args = oauth2.bearer_header(client, cis, request_args, http_args={"foo": "bar"})

    print cis
    print http_args
    assert _eq(http_args.keys(), ["foo", "headers"])
    assert http_args["headers"] == {"Authorization": "Bearer Sesame"}

    # -----------------

    request_args = {"access_token": "Sesame"}

    http_args = oauth2.bearer_header(client, cis, request_args, http_args={"headers": {"x-foo": "bar"}})

    print cis
    print http_args
    assert _eq(http_args.keys(), ["headers"])
    assert _eq(http_args["headers"].keys(), ["Authorization", "x-foo"])
    assert http_args["headers"]["Authorization"] == "Bearer Sesame"
Ejemplo n.º 2
0
def test_bearer_header_2():
    client = Client("A")
    client.client_secret = "boarding pass"

    cis = ResourceRequest(access_token="Sesame")

    http_args = oauth2.bearer_header(client, cis)

    print cis
    assert "access_token" not in cis
    print http_args
    assert http_args == {"headers": {"Authorization": "Bearer Sesame"}}
Ejemplo n.º 3
0
def test_bearer_header_3():
    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()

    http_args = oauth2.bearer_header(client, cis)

    print cis
    assert "access_token" not in cis
    print http_args
    assert http_args == {"headers": {"Authorization": "Bearer token1"}}