mypy changes

This commit is contained in:
mike cullerton 2022-07-06 08:30:45 -04:00
parent 7e0c06aaa5
commit 8d9eb7e54e
2 changed files with 17 additions and 21 deletions

View File

@ -1,19 +1,16 @@
"""Authentication_service."""
from keycloak import KeycloakOpenID
from keycloak.uma_permissions import AuthStatus # type: ignore
from typing import Optional
from keycloak import KeycloakOpenID # type: ignore
from keycloak.uma_permissions import AuthStatus # type: ignore
class AuthenticationService:
"""AuthenticationService."""
@staticmethod
def get_keycloak_openid(
server_url: str,
client_id: str,
realm_name: str,
client_secret_key: str
server_url: str, client_id: str, realm_name: str, client_secret_key: str
) -> KeycloakOpenID:
"""Get_keycloak_openid."""
keycloak_openid = KeycloakOpenID(
@ -24,6 +21,7 @@ class AuthenticationService:
)
return keycloak_openid
# Might not need this
# @staticmethod
# def get_keycloak_token(keycloak_openid, user, password):
# """Get_keycloak_token."""
@ -31,44 +29,42 @@ class AuthenticationService:
# return token
@staticmethod
def get_permission_by_token(keycloak_openid: KeycloakOpenID, token: dict) -> Optional[list[dict]]:
def get_permission_by_token(
keycloak_openid: KeycloakOpenID, token: dict
) -> Optional[list[dict]]:
"""Get_permission_by_token."""
# Get permissions by token
# KEYCLOAK_PUBLIC_KEY = keycloak_openid.public_key()
# KEYCLOAK_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\n" + keycloak_openid.public_key() + "\n-----END PUBLIC KEY-----"
# policies = keycloak_openid.get_policies(token['access_token'], method_token_info='decode',
# key=KEYCLOAK_PUBLIC_KEY)
permissions = keycloak_openid.get_permissions(
permissions: list = keycloak_openid.get_permissions(
token["access_token"], method_token_info="introspect"
)
# TODO: Not sure if this is good. Permissions comes back as None
return permissions
@staticmethod
def get_uma_permissions_by_token(keycloak_openid: KeycloakOpenID, token: dict) -> Optional[list[dict]]:
def get_uma_permissions_by_token(
keycloak_openid: KeycloakOpenID, token: dict
) -> Optional[list[dict]]:
"""Get_uma_permissions_by_token."""
permissions = keycloak_openid.uma_permissions(token["access_token"])
permissions: list = keycloak_openid.uma_permissions(token["access_token"])
return permissions
@staticmethod
def get_uma_permissions_by_token_for_resource_and_scope(
keycloak_openid: KeycloakOpenID,
token: dict,
resource: str,
scope: str
keycloak_openid: KeycloakOpenID, token: dict, resource: str, scope: str
) -> Optional[list[dict]]:
"""Get_uma_permissions_by_token_for_resource_and_scope."""
permissions = keycloak_openid.uma_permissions(
permissions: list = keycloak_openid.uma_permissions(
token["access_token"], permissions=f"{resource}#{scope}"
)
return permissions
@staticmethod
def get_auth_status_for_resource_and_scope_by_token(
keycloak_openid: KeycloakOpenID,
token: dict,
resource: str,
scope: str
keycloak_openid: KeycloakOpenID, token: dict, resource: str, scope: str
) -> AuthStatus:
"""Get_auth_status_for_resource_and_scope_by_token."""
auth_status = keycloak_openid.has_uma_access(

View File

@ -52,7 +52,7 @@ def test_get_permission_by_token() -> None:
permissions = AuthenticationService.get_permission_by_token(keycloak_openid, token)
# TODO: permissions comes back as None. Is this right?
print("test_get_permission_by_token")
print(f"test_get_permission_by_token: {permissions}")
def test_get_uma_permissions_by_token() -> None: