Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PPS-928 update authutils #85

Merged
merged 9 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
306 changes: 152 additions & 154 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ license = "Apache-2.0"
[tool.poetry.dependencies]
python = "^3.9"
alembic = "^1.4.1"
Authlib = "^0.14.3"
authutils = "^5.0.5"
authutils = "^6.0.0"
cdiserrors = "^1.0.0"
cdislogging = "^1.0.0"
cryptography = ">=42.0.0"
Expand Down
18 changes: 16 additions & 2 deletions tests/app_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,25 @@ def test_authorize_endpoint(client, test_user, db_session, auth_header):
# decoded id_token for IdP "default":
{"context": {"user": {"name": test_user.username}}},
# decoded refresh_token for IdP "default":
{"jti": str(uuid.uuid4()), "exp": now + 100, "sub": test_user.userid},
{
"jti": str(uuid.uuid4()),
"exp": now + 100,
"sub": test_user.userid,
"scope": ["openid", "access", "user", "test_aud"],
"aud": "https://localhost/user",
"iss": "https://localhost/user",
},
# decoded id_token for IdP "idp_a":
{"context": {"user": {"name": test_user.username}}},
# decoded refresh_token for IdP "idp_a":
{"jti": str(uuid.uuid4()), "exp": now + 100, "sub": test_user.userid},
{
"jti": str(uuid.uuid4()),
"exp": now + 100,
"sub": test_user.userid,
"scope": ["openid", "access", "user", "test_aud"],
"aud": "https://localhost/user",
"iss": "https://localhost/user",
},
]
patched_jwt_decode = mock.patch("jose.jwt.decode", mocked_jwt_response)
patched_jwt_decode.start()
Expand Down
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,22 @@ def auth_header(test_user, rsa_private_key, default_kid):
List[Tuple[str, str]]: the authorization header
"""
now = int(time.time())
default_audiences = ["openid", "access", "user", "test_aud"]
default_scopes = ["openid", "access", "user", "test_aud"]
claims = {
"pur": "access",
"aud": default_audiences,
"aud": "https://localhost/user",
"sub": test_user.userid,
"iss": "https://localhost/user",
"iat": now,
"exp": now + 600,
"jti": str(uuid.uuid4()),
"scope": default_scopes,
"context": {"user": {"name": test_user.username, "projects": []}},
}
token_headers = {"kid": default_kid}
encoded_jwt = jwt.encode(
claims, headers=token_headers, key=rsa_private_key, algorithm="RS256"
)
encoded_jwt = encoded_jwt.decode("utf-8")
return [("Authorization", "Bearer {}".format(encoded_jwt))]


Expand Down
3 changes: 3 additions & 0 deletions wts/auth_plugins/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ def find_user(self):
flask.current_app.config["OIDC_ISSUER"] = default_oauth_client.metadata[
"api_base_url"
].rstrip("/")
flask.current_app.config["USER_API"] = default_oauth_client.metadata[
"api_base_url"
].rstrip("/")

user = current_user
return User(userid=user.id, username=user.username)
1 change: 1 addition & 0 deletions wts/blueprints/external_oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def get_external_oidc():
# to know the issuer
client = get_oauth_client(idp="default")
flask.current_app.config["OIDC_ISSUER"] = client.metadata["api_base_url"].strip("/")
flask.current_app.config["USER_API"] = client.metadata["api_base_url"].rstrip("/")
username = None
try:
user = current_user
Expand Down
1 change: 1 addition & 0 deletions wts/blueprints/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def connected():
# to know the issuer
client = get_oauth_client(idp=requested_idp)
flask.current_app.config["OIDC_ISSUER"] = client.metadata["api_base_url"].strip("/")
flask.current_app.config["USER_API"] = client.metadata["api_base_url"].rstrip("/")

try:
user = current_user
Expand Down
1 change: 1 addition & 0 deletions wts/resources/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def refresh_refresh_token(tokens, idp, username_field):
# to know the issuer
client = get_oauth_client(idp="default")
flask.current_app.config["OIDC_ISSUER"] = client.metadata["api_base_url"].strip("/")
flask.current_app.config["USER_API"] = client.metadata["api_base_url"].rstrip("/")
user = current_user
username = user.username

Expand Down
Loading