MCPcopy
hub / github.com/authlib/authlib / test_oauth2_authorize

Function test_oauth2_authorize

tests/clients/test_django/test_oauth_client.py:95–120  ·  view source on GitHub ↗
(factory)

Source from the content-addressed store, hash-verified

93
94
95def test_oauth2_authorize(factory):
96 request = factory.get("/login")
97 request.session = factory.session
98
99 oauth = OAuth()
100 client = oauth.register(
101 "dev",
102 client_id="dev",
103 client_secret="dev",
104 api_base_url="https://resource.test/api",
105 access_token_url="https://provider.test/token",
106 authorize_url="https://provider.test/authorize",
107 )
108 rv = client.authorize_redirect(request, "https://client.test/callback")
109 assert rv.status_code == 302
110 url = rv.get("Location")
111 assert "state=" in url
112 state = dict(url_decode(urlparse.urlparse(url).query))["state"]
113
114 with mock.patch("requests.sessions.Session.send") as send:
115 send.return_value = mock_send_value(get_bearer_token())
116 request2 = factory.get(f"/authorize?state={state}&code=foo")
117 request2.session = request.session
118
119 token = client.authorize_access_token(request2)
120 assert token["access_token"] == "a"
121
122
123def test_oauth2_authorize_access_denied(factory):

Callers

nothing calls this directly

Calls 9

registerMethod · 0.95
OAuthClass · 0.90
url_decodeFunction · 0.90
mock_send_valueFunction · 0.85
get_bearer_tokenFunction · 0.85
patchMethod · 0.80
getMethod · 0.45
authorize_redirectMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…