예제 #1
0
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"
예제 #2
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"}}
예제 #3
0
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()

    _ = BearerBody(client).construct(cis)

    assert "access_token" in cis
    assert cis["access_token"] == "token1"
예제 #4
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 = BearerHeader(client).construct(cis)

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