MCPcopy
hub / github.com/authlib/authlib / test_authorize_token

Function test_authorize_token

tests/flask/test_oauth2/test_openid_code_grant.py:79–124  ·  view source on GitHub ↗
(test_client, server)

Source from the content-addressed store, hash-verified

77
78
79def test_authorize_token(test_client, server):
80 register_oidc_code_grant(
81 server,
82 )
83 auth_request_time = time.time()
84 rv = test_client.post(
85 "/oauth/authorize",
86 data={
87 "response_type": "code",
88 "client_id": "client-id",
89 "state": "bar",
90 "scope": "openid profile",
91 "redirect_uri": "https://client.test",
92 "user_id": "1",
93 },
94 )
95 assert "code=" in rv.location
96
97 params = dict(url_decode(urlparse.urlparse(rv.location).query))
98 assert params["state"] == "bar"
99
100 code = params["code"]
101 headers = create_basic_header("client-id", "client-secret")
102 rv = test_client.post(
103 "/oauth/token",
104 data={
105 "grant_type": "authorization_code",
106 "redirect_uri": "https://client.test",
107 "code": code,
108 },
109 headers=headers,
110 )
111 resp = json.loads(rv.data)
112 assert "access_token" in resp
113 assert "id_token" in resp
114
115 token = jwt.decode(resp["id_token"], key=OctKey.import_key("secret"))
116 claims = CodeIDToken(
117 token.claims,
118 token.header,
119 {"iss": {"value": "Authlib"}},
120 )
121 claims.validate()
122 assert claims["auth_time"] >= int(auth_request_time)
123 assert claims["acr"] == "urn:mace:incommon:iap:silver"
124 assert claims["amr"] == ["pwd", "otp"]
125
126
127def test_pure_code_flow(test_client, server):

Callers

nothing calls this directly

Calls 8

url_decodeFunction · 0.90
CodeIDTokenClass · 0.90
register_oidc_code_grantFunction · 0.85
create_basic_headerFunction · 0.85
postMethod · 0.80
decodeMethod · 0.80
import_keyMethod · 0.45
validateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…