canaille-globuzma/tests/oidc/test_authorization_code_flow.py

792 lines
23 KiB
Python
Raw Normal View History

import datetime
import logging
2021-12-20 22:57:27 +00:00
from urllib.parse import parse_qs
from urllib.parse import urlsplit
import time_machine
2021-10-13 09:52:02 +00:00
from authlib.jose import jwt
2020-08-25 13:28:13 +00:00
from authlib.oauth2.rfc7636 import create_s256_code_challenge
2023-08-13 20:08:28 +00:00
from flask import g
2020-08-25 13:28:13 +00:00
from werkzeug.security import gen_salt
2020-08-19 08:28:28 +00:00
from canaille.app import models
2021-12-20 22:57:27 +00:00
from . import client_credentials
2020-08-19 08:28:28 +00:00
def test_nominal_case(
testclient, logged_user, client, keypair, trusted_client, backend, caplog
):
assert not backend.query(models.Consent)
2022-05-20 07:24:24 +00:00
2020-08-19 08:28:28 +00:00
res = testclient.get(
"/oauth/authorize",
params=dict(
response_type="code",
client_id=client.client_id,
2022-07-07 14:05:34 +00:00
scope="openid profile email groups address phone",
2020-08-19 08:28:28 +00:00
nonce="somenonce",
),
2020-10-30 18:19:34 +00:00
status=200,
2020-08-19 08:28:28 +00:00
)
2020-10-30 22:41:02 +00:00
res = res.form.submit(name="answer", value="accept", status=302)
assert (
"canaille",
logging.SECURITY,
"New consent for user in client Some client from unknown IP",
) in caplog.record_tuples
2020-08-24 08:52:21 +00:00
assert res.location.startswith(client.redirect_uris[0])
2020-08-24 08:52:21 +00:00
params = parse_qs(urlsplit(res.location).query)
code = params["code"][0]
authcode = backend.get(models.AuthorizationCode, code=code)
2020-08-24 08:52:21 +00:00
assert authcode is not None
assert set(authcode.scope) == {
2022-07-07 14:05:34 +00:00
"openid",
"profile",
"email",
"groups",
"address",
"phone",
}
2020-08-24 08:52:21 +00:00
consents = backend.query(models.Consent, client=client, subject=logged_user)
2022-07-07 14:05:34 +00:00
assert set(consents[0].scope) == {
"openid",
"profile",
"email",
"groups",
"address",
"phone",
}
2022-05-20 07:24:24 +00:00
2020-08-24 08:52:21 +00:00
res = testclient.post(
"/oauth/token",
params=dict(
grant_type="authorization_code",
code=code,
2022-07-07 14:05:34 +00:00
scope="openid profile email groups address phone",
redirect_uri=client.redirect_uris[0],
2020-08-24 08:52:21 +00:00
),
headers={"Authorization": f"Basic {client_credentials(client)}"},
2020-10-30 18:19:34 +00:00
status=200,
2020-08-24 08:52:21 +00:00
)
2021-10-13 09:52:02 +00:00
access_token = res.json["access_token"]
token = backend.get(models.Token, access_token=access_token)
assert token.client == client
assert token.subject == logged_user
assert set(token.scope) == {
2022-07-07 14:05:34 +00:00
"openid",
"profile",
"email",
"groups",
"address",
"phone",
}
claims = jwt.decode(access_token, keypair[1])
assert claims["sub"] == logged_user.user_name
assert claims["name"] == logged_user.formatted_name
assert claims["aud"] == [client.client_id, trusted_client.client_id]
2020-08-24 08:52:21 +00:00
2021-10-13 09:52:02 +00:00
id_token = res.json["id_token"]
claims = jwt.decode(id_token, keypair[1])
assert claims["sub"] == logged_user.user_name
assert claims["name"] == logged_user.formatted_name
assert claims["aud"] == [client.client_id, trusted_client.client_id]
assert (
"canaille",
logging.SECURITY,
"Issued authorization_code token for user in client Some client from unknown IP",
) in caplog.record_tuples
2020-09-25 09:26:41 +00:00
res = testclient.get(
2020-10-30 18:19:34 +00:00
"/oauth/userinfo",
headers={"Authorization": f"Bearer {access_token}"},
status=200,
2020-09-25 09:26:41 +00:00
)
2022-12-24 00:44:16 +00:00
assert res.json["name"] == "John (johnny) Doe"
2020-08-24 08:52:21 +00:00
2022-05-20 07:24:24 +00:00
for consent in consents:
backend.delete(consent)
2022-05-20 07:24:24 +00:00
2020-08-24 08:52:21 +00:00
def test_invalid_client(testclient, logged_user, keypair):
2023-05-25 11:37:58 +00:00
testclient.get(
"/oauth/authorize",
params=dict(
response_type="code",
client_id="invalid",
scope="openid profile email groups address phone",
nonce="somenonce",
),
status=400,
)
def test_redirect_uri(
testclient, logged_user, client, keypair, trusted_client, backend
):
assert not backend.query(models.Consent)
res = testclient.get(
"/oauth/authorize",
params=dict(
response_type="code",
client_id=client.client_id,
scope="openid profile email groups address phone",
nonce="somenonce",
redirect_uri=client.redirect_uris[1],
),
status=200,
)
res = res.form.submit(name="answer", value="accept", status=302)
assert res.location.startswith(client.redirect_uris[1])
params = parse_qs(urlsplit(res.location).query)
code = params["code"][0]
authcode = backend.get(models.AuthorizationCode, code=code)
assert authcode is not None
consents = backend.query(models.Consent, client=client, subject=logged_user)
res = testclient.post(
"/oauth/token",
params=dict(
grant_type="authorization_code",
code=code,
scope="openid profile email groups address phone",
redirect_uri=client.redirect_uris[1],
),
headers={"Authorization": f"Basic {client_credentials(client)}"},
status=200,
)
access_token = res.json["access_token"]
token = backend.get(models.Token, access_token=access_token)
assert token.client == client
assert token.subject == logged_user
for consent in consents:
backend.delete(consent)
def test_preconsented_client(
testclient, logged_user, client, keypair, trusted_client, backend
):
assert not backend.query(models.Consent)
2022-05-20 07:24:24 +00:00
client.preconsent = True
backend.save(client)
2021-10-20 10:05:08 +00:00
res = testclient.get(
"/oauth/authorize",
params=dict(
response_type="code",
client_id=client.client_id,
scope="openid profile",
2021-10-20 10:05:08 +00:00
nonce="somenonce",
),
status=302,
)
assert res.location.startswith(client.redirect_uris[0])
2021-10-20 10:05:08 +00:00
params = parse_qs(urlsplit(res.location).query)
code = params["code"][0]
authcode = backend.get(models.AuthorizationCode, code=code)
2021-10-20 10:05:08 +00:00
assert authcode is not None
consents = backend.query(models.Consent, client=client, subject=logged_user)
2022-05-20 07:24:24 +00:00
assert not consents
2021-10-20 10:05:08 +00:00
res = testclient.post(
"/oauth/token",
params=dict(
grant_type="authorization_code",
code=code,
scope="openid profile",
redirect_uri=client.redirect_uris[0],
2021-10-20 10:05:08 +00:00
),
headers={"Authorization": f"Basic {client_credentials(client)}"},
status=200,
)
access_token = res.json["access_token"]
token = backend.get(models.Token, access_token=access_token)
assert token.client == client
assert token.subject == logged_user
2021-10-20 10:05:08 +00:00
id_token = res.json["id_token"]
claims = jwt.decode(id_token, keypair[1])
assert logged_user.user_name == claims["sub"]
assert logged_user.formatted_name == claims["name"]
assert [client.client_id, trusted_client.client_id] == claims["aud"]
2021-10-20 10:05:08 +00:00
res = testclient.get(
"/oauth/userinfo",
headers={"Authorization": f"Bearer {access_token}"},
status=200,
)
2022-12-24 00:44:16 +00:00
assert res.json["name"] == "John (johnny) Doe"
2021-10-20 10:05:08 +00:00
def test_logout_login(testclient, logged_user, client, backend):
assert not backend.query(models.Consent)
2022-05-20 07:24:24 +00:00
2020-08-24 08:52:21 +00:00
res = testclient.get(
"/oauth/authorize",
params=dict(
response_type="code",
client_id=client.client_id,
scope="openid profile",
2020-08-24 08:52:21 +00:00
nonce="somenonce",
),
2020-10-30 18:19:34 +00:00
status=200,
2020-08-24 08:52:21 +00:00
)
res = res.form.submit(name="answer", value="logout")
res = res.follow()
2023-08-13 20:08:28 +00:00
g.user = None
res = res.follow()
res = res.follow()
2020-08-24 08:52:21 +00:00
res.form["login"] = logged_user.user_name
res = res.form.submit()
res = res.follow()
2020-08-24 08:54:50 +00:00
res.form["password"] = "wrong password"
2020-10-30 22:41:02 +00:00
res = res.form.submit(status=200)
assert ("error", "Login failed, please check your information") in res.flashes
2020-08-24 08:54:50 +00:00
res.form["password"] = "correct horse battery staple"
2020-10-30 22:41:02 +00:00
res = res.form.submit(status=302)
res = res.follow(status=200)
2020-08-19 08:28:28 +00:00
2020-10-30 22:41:02 +00:00
res = res.form.submit(name="answer", value="accept", status=302)
2020-10-28 16:57:27 +00:00
assert res.location.startswith(client.redirect_uris[0])
2020-08-19 08:28:28 +00:00
params = parse_qs(urlsplit(res.location).query)
code = params["code"][0]
authcode = backend.get(models.AuthorizationCode, code=code)
2020-08-19 08:28:28 +00:00
assert authcode is not None
consents = backend.query(models.Consent, client=client, subject=logged_user)
2022-05-20 07:24:24 +00:00
assert "profile" in consents[0].scope
2020-08-19 08:28:28 +00:00
res = testclient.post(
"/oauth/token",
params=dict(
grant_type="authorization_code",
code=code,
scope="openid profile",
redirect_uri=client.redirect_uris[0],
2020-08-19 08:28:28 +00:00
),
headers={"Authorization": f"Basic {client_credentials(client)}"},
2020-10-30 18:19:34 +00:00
status=200,
2020-08-19 08:28:28 +00:00
)
2021-10-13 09:52:02 +00:00
access_token = res.json["access_token"]
token = backend.get(models.Token, access_token=access_token)
assert token.client == client
assert token.subject == logged_user
2020-08-19 08:28:28 +00:00
2020-09-25 09:26:41 +00:00
res = testclient.get(
2020-10-30 18:19:34 +00:00
"/oauth/userinfo",
headers={"Authorization": f"Bearer {access_token}"},
status=200,
2020-09-25 09:26:41 +00:00
)
2022-12-24 00:44:16 +00:00
assert res.json["name"] == "John (johnny) Doe"
2020-08-24 08:52:21 +00:00
2022-05-20 07:24:24 +00:00
for consent in consents:
backend.delete(consent)
2022-05-20 07:24:24 +00:00
2020-08-24 08:52:21 +00:00
def test_deny(testclient, logged_user, client, backend):
assert not backend.query(models.Consent)
2022-12-11 13:43:21 +00:00
res = testclient.get(
"/oauth/authorize",
params=dict(
response_type="code",
client_id=client.client_id,
scope="openid profile",
nonce="somenonce",
),
status=200,
)
res = res.form.submit(name="answer", value="deny", status=302)
assert res.location.startswith(client.redirect_uris[0])
params = parse_qs(urlsplit(res.location).query)
error = params["error"][0]
assert error == "access_denied"
assert not backend.query(models.Consent)
2022-12-11 13:43:21 +00:00
def test_code_challenge(testclient, logged_user, client, backend):
assert not backend.query(models.Consent)
2022-05-20 07:24:24 +00:00
client.token_endpoint_auth_method = "none"
backend.save(client)
2020-08-25 13:51:49 +00:00
2020-08-25 13:28:13 +00:00
code_verifier = gen_salt(48)
code_challenge = create_s256_code_challenge(code_verifier)
res = testclient.get(
"/oauth/authorize",
params=dict(
code_challenge=code_challenge,
code_challenge_method="S256",
response_type="code",
client_id=client.client_id,
scope="openid profile",
2020-08-25 13:28:13 +00:00
nonce="somenonce",
),
2020-10-30 18:19:34 +00:00
status=200,
2020-08-25 13:28:13 +00:00
)
2020-10-30 22:41:02 +00:00
res = res.form.submit(name="answer", value="accept", status=302)
2020-08-25 13:28:13 +00:00
assert res.location.startswith(client.redirect_uris[0])
2020-08-25 13:28:13 +00:00
params = parse_qs(urlsplit(res.location).query)
code = params["code"][0]
authcode = backend.get(models.AuthorizationCode, code=code)
2020-08-25 13:28:13 +00:00
assert authcode is not None
consents = backend.query(models.Consent, client=client, subject=logged_user)
2022-05-20 07:24:24 +00:00
assert "profile" in consents[0].scope
2020-08-25 13:28:13 +00:00
res = testclient.post(
"/oauth/token",
params=dict(
grant_type="authorization_code",
code=code,
scope="openid profile",
2020-08-25 13:28:13 +00:00
code_verifier=code_verifier,
redirect_uri=client.redirect_uris[0],
client_id=client.client_id,
2020-08-25 13:28:13 +00:00
),
2020-10-30 18:19:34 +00:00
status=200,
2020-08-25 13:28:13 +00:00
)
access_token = res.json["access_token"]
token = backend.get(models.Token, access_token=access_token)
assert token.client == client
assert token.subject == logged_user
2020-08-25 13:28:13 +00:00
2020-09-25 09:26:41 +00:00
res = testclient.get(
2020-10-30 18:19:34 +00:00
"/oauth/userinfo",
headers={"Authorization": f"Bearer {access_token}"},
status=200,
2020-09-25 09:26:41 +00:00
)
2022-12-24 00:44:16 +00:00
assert res.json["name"] == "John (johnny) Doe"
2020-08-25 13:51:49 +00:00
client.token_endpoint_auth_method = "client_secret_basic"
backend.save(client)
2020-09-17 08:00:39 +00:00
2022-05-20 07:24:24 +00:00
for consent in consents:
backend.delete(consent)
2022-05-20 07:24:24 +00:00
2020-09-17 08:00:39 +00:00
def test_consent_already_given(testclient, logged_user, client, backend):
assert not backend.query(models.Consent)
2020-09-17 08:00:39 +00:00
res = testclient.get(
"/oauth/authorize",
params=dict(
response_type="code",
client_id=client.client_id,
scope="openid profile",
2020-09-17 08:00:39 +00:00
nonce="somenonce",
),
2020-10-30 18:19:34 +00:00
status=200,
2020-09-17 08:00:39 +00:00
)
2020-10-30 22:41:02 +00:00
res = res.form.submit(name="answer", value="accept", status=302)
2020-09-17 08:00:39 +00:00
assert res.location.startswith(client.redirect_uris[0])
2020-09-17 08:00:39 +00:00
params = parse_qs(urlsplit(res.location).query)
code = params["code"][0]
authcode = backend.get(models.AuthorizationCode, code=code)
2020-09-17 08:00:39 +00:00
assert authcode is not None
consents = backend.query(models.Consent, client=client, subject=logged_user)
assert "profile" in consents[0].scope
2020-09-17 08:00:39 +00:00
res = testclient.post(
"/oauth/token",
params=dict(
grant_type="authorization_code",
code=code,
scope="openid profile",
redirect_uri=client.redirect_uris[0],
2020-09-17 08:00:39 +00:00
),
headers={"Authorization": f"Basic {client_credentials(client)}"},
2020-10-30 18:19:34 +00:00
status=200,
2020-09-17 08:00:39 +00:00
)
assert "access_token" in res.json
res = testclient.get(
"/oauth/authorize",
params=dict(
response_type="code",
client_id=client.client_id,
scope="openid profile",
2020-09-17 08:00:39 +00:00
nonce="somenonce",
),
2020-10-30 22:41:02 +00:00
status=302,
2020-09-17 08:00:39 +00:00
)
assert res.location.startswith(client.redirect_uris[0])
2020-09-17 08:00:39 +00:00
params = parse_qs(urlsplit(res.location).query)
assert "code" in params
2022-05-20 07:24:24 +00:00
for consent in consents:
backend.delete(consent)
2022-05-20 07:24:24 +00:00
2020-09-17 08:00:39 +00:00
def test_when_consent_already_given_but_for_a_smaller_scope(
testclient, logged_user, client, backend
):
assert not backend.query(models.Consent)
res = testclient.get(
"/oauth/authorize",
params=dict(
response_type="code",
client_id=client.client_id,
scope="openid profile",
nonce="somenonce",
),
status=200,
)
res = res.form.submit(name="answer", value="accept", status=302)
assert res.location.startswith(client.redirect_uris[0])
params = parse_qs(urlsplit(res.location).query)
code = params["code"][0]
authcode = backend.get(models.AuthorizationCode, code=code)
assert authcode is not None
consents = backend.query(models.Consent, client=client, subject=logged_user)
assert "profile" in consents[0].scope
assert "groups" not in consents[0].scope
res = testclient.post(
"/oauth/token",
params=dict(
grant_type="authorization_code",
code=code,
scope="openid profile",
redirect_uri=client.redirect_uris[0],
),
headers={"Authorization": f"Basic {client_credentials(client)}"},
status=200,
)
assert "access_token" in res.json
res = testclient.get(
"/oauth/authorize",
params=dict(
response_type="code",
client_id=client.client_id,
scope="openid profile groups",
nonce="somenonce",
),
status=200,
)
res = res.form.submit(name="answer", value="accept", status=302)
assert res.location.startswith(client.redirect_uris[0])
params = parse_qs(urlsplit(res.location).query)
code = params["code"][0]
authcode = backend.get(models.AuthorizationCode, code=code)
assert authcode is not None
consents = backend.query(models.Consent, client=client, subject=logged_user)
assert "profile" in consents[0].scope
assert "groups" in consents[0].scope
2022-05-20 07:24:24 +00:00
for consent in consents:
backend.delete(consent)
2022-05-20 07:24:24 +00:00
def test_user_cannot_use_oidc(
testclient, user, client, keypair, trusted_client, backend
):
testclient.app.config["CANAILLE"]["ACL"]["DEFAULT"]["PERMISSIONS"] = []
backend.reload(user)
2021-12-06 23:07:32 +00:00
res = testclient.get(
"/oauth/authorize",
params=dict(
response_type="code",
client_id=client.client_id,
scope="openid profile",
2021-12-06 23:07:32 +00:00
nonce="somenonce",
),
)
res = res.follow()
2021-12-06 23:07:32 +00:00
res.form["login"] = "user"
res = res.form.submit()
res = res.follow()
2021-12-06 23:07:32 +00:00
res.form["password"] = "correct horse battery staple"
res = res.form.submit(status=302)
res = res.follow(status=403)
2021-12-06 23:07:32 +00:00
def test_nonce_required_in_oidc_requests(testclient, logged_user, client):
res = testclient.get(
"/oauth/authorize",
params=dict(
response_type="code",
client_id=client.client_id,
scope="openid profile",
),
status=200,
)
assert res.json.get("error") == "invalid_request"
def test_nonce_not_required_in_oauth_requests(testclient, logged_user, client, backend):
assert not backend.query(models.Consent)
testclient.app.config["CANAILLE_OIDC"]["REQUIRE_NONCE"] = False
res = testclient.get(
"/oauth/authorize",
params=dict(
response_type="code",
client_id=client.client_id,
scope="profile",
),
status=200,
)
res = res.form.submit(name="answer", value="accept", status=302)
assert res.location.startswith(client.redirect_uris[0])
for consent in backend.query(models.Consent):
backend.delete(consent)
2022-07-07 14:05:34 +00:00
def test_request_scope_too_large(testclient, logged_user, keypair, client, backend):
assert not backend.query(models.Consent)
client.scope = ["openid", "profile", "groups"]
backend.save(client)
2022-07-07 14:05:34 +00:00
res = testclient.get(
"/oauth/authorize",
params=dict(
response_type="code",
client_id=client.client_id,
2022-07-07 14:05:34 +00:00
scope="openid profile email",
nonce="somenonce",
),
status=200,
)
res = res.form.submit(name="answer", value="accept", status=302)
params = parse_qs(urlsplit(res.location).query)
code = params["code"][0]
authcode = backend.get(models.AuthorizationCode, code=code)
assert set(authcode.scope) == {
2022-07-07 14:05:34 +00:00
"openid",
"profile",
}
consents = backend.query(models.Consent, client=client, subject=logged_user)
2022-07-07 14:05:34 +00:00
assert set(consents[0].scope) == {
"openid",
"profile",
}
res = testclient.post(
"/oauth/token",
params=dict(
grant_type="authorization_code",
code=code,
scope="openid profile email groups address phone",
redirect_uri=client.redirect_uris[0],
2022-07-07 14:05:34 +00:00
),
headers={"Authorization": f"Basic {client_credentials(client)}"},
2022-07-07 14:05:34 +00:00
status=200,
)
access_token = res.json["access_token"]
token = backend.get(models.Token, access_token=access_token)
assert token.client == client
assert token.subject == logged_user
assert set(token.scope) == {
2022-07-07 14:05:34 +00:00
"openid",
"profile",
}
id_token = res.json["id_token"]
claims = jwt.decode(id_token, keypair[1])
assert logged_user.user_name == claims["sub"]
assert logged_user.formatted_name == claims["name"]
2022-07-07 14:05:34 +00:00
res = testclient.get(
"/oauth/userinfo",
headers={"Authorization": f"Bearer {access_token}"},
status=200,
)
2022-12-24 00:44:16 +00:00
assert res.json["name"] == "John (johnny) Doe"
2022-07-07 14:05:34 +00:00
for consent in consents:
backend.delete(consent)
def test_code_expired(testclient, user, client):
with time_machine.travel("2020-01-01 01:00:00+00:00", tick=False):
res = testclient.get(
"/oauth/authorize",
params=dict(
response_type="code",
client_id=client.client_id,
scope="openid profile email groups address phone",
nonce="somenonce",
),
)
res = res.follow()
res.form["login"] = "user"
res = res.form.submit(name="answer", value="accept").follow()
res.form["password"] = "correct horse battery staple"
res = res.form.submit(name="answer", value="accept").follow()
res = res.form.submit(name="answer", value="accept", status=302)
params = parse_qs(urlsplit(res.location).query)
code = params["code"][0]
with time_machine.travel("2021-01-01 01:00:00+00:00", tick=False):
res = testclient.post(
"/oauth/token",
params=dict(
grant_type="authorization_code",
code=code,
scope="openid profile email groups address phone",
redirect_uri=client.redirect_uris[0],
),
headers={"Authorization": f"Basic {client_credentials(client)}"},
status=400,
)
assert res.json == {
"error": "invalid_grant",
"error_description": 'Invalid "code" in request.',
}
def test_code_with_invalid_user(testclient, admin, client, backend):
user = models.User(
formatted_name="John Doe",
family_name="Doe",
user_name="temp",
emails=["temp@temp.test"],
2023-04-10 19:42:14 +00:00
password="correct horse battery staple",
)
backend.save(user)
res = testclient.get(
"/oauth/authorize",
params=dict(
response_type="code",
client_id=client.client_id,
scope="openid profile email groups address phone",
nonce="somenonce",
),
).follow()
res.form["login"] = "temp"
res = res.form.submit(name="answer", value="accept", status=302).follow()
res.form["password"] = "correct horse battery staple"
res = res.form.submit(name="answer", value="accept", status=302).follow()
res = res.form.submit(name="answer", value="accept", status=302)
params = parse_qs(urlsplit(res.location).query)
code = params["code"][0]
authcode = backend.get(models.AuthorizationCode, code=code)
backend.delete(user)
res = testclient.post(
"/oauth/token",
params=dict(
grant_type="authorization_code",
code=code,
scope="openid profile email groups address phone",
redirect_uri=client.redirect_uris[0],
),
headers={"Authorization": f"Basic {client_credentials(client)}"},
status=400,
)
assert res.json == {
"error": "invalid_grant",
"error_description": 'There is no "user" for this code.',
}
backend.delete(authcode)
def test_locked_account(
testclient, logged_user, client, keypair, trusted_client, backend
):
"""Users with a locked account should not be able to exchange code against
tokens."""
res = testclient.get(
"/oauth/authorize",
params=dict(
response_type="code",
client_id=client.client_id,
scope="openid profile email groups address phone",
nonce="somenonce",
),
status=200,
)
logged_user.lock_date = datetime.datetime.now(datetime.timezone.utc)
backend.save(logged_user)
res = res.form.submit(name="answer", value="accept", status=302)
assert res.location.startswith(client.redirect_uris[0])
params = parse_qs(urlsplit(res.location).query)
code = params["code"][0]
authcode = backend.get(models.AuthorizationCode, code=code)
assert authcode is not None
res = testclient.post(
"/oauth/token",
params=dict(
grant_type="authorization_code",
code=code,
scope="openid profile email groups address phone",
redirect_uri=client.redirect_uris[0],
),
headers={"Authorization": f"Basic {client_credentials(client)}"},
status=400,
)
assert "access_token" not in res.json
def test_missing_client_id(
testclient, logged_user, client, keypair, trusted_client, backend
):
"""Missing client_id should raise a 400 error."""
res = testclient.get(
"/oauth/authorize",
params=dict(
response_type="code",
scope="openid profile email groups address phone",
nonce="somenonce",
),
status=400,
)
res.mustcontain("client_id parameter is missing.")