Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
disrupted committed Feb 26, 2024
1 parent 4050978 commit ae05cfb
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions keycloak/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class KeycloakOAuth2:
def __init__(
self,
client_id: str,
client_secret: str | bytes,
client_secret: str | bytes | None,
server_metadata_url: str,
client_kwargs: dict[str, Any],
base_url: str = "/",
Expand All @@ -39,24 +39,25 @@ def __init__(

# TODO pass properly
# Generated via `openssl genrsa - out keypair.pem 2048`
client_secret = Path("keypair.pem").read_bytes()
if not client_secret:
client_secret = Path("keypair.pem").read_bytes()

# Generated via `openssl rsa -in keypair.pem -pubout -out publickey.crt`
self.pub = JsonWebKey.import_key(
Path("publickey.crt").read_text(), {"kty": "RSA", "use": "sig"}
).as_dict()
# Generated via `openssl rsa -in keypair.pem -pubout -out publickey.crt`
self.pub = JsonWebKey.import_key(
Path("publickey.crt").read_text(), {"kty": "RSA", "use": "sig"}
).as_dict()

# TODO call self.keycloak.load_server_metadata() and get token_endpoint
token_endpoint = (
"http://localhost:8180/realms/daewy/protocol/openid-connect/token"
)
auth_method = PrivateKeyJWT(token_endpoint)
client_kwargs.update(
{
"client_auth_methods": [auth_method],
"token_endpoint_auth_method": auth_method.name,
}
)
# TODO call self.keycloak.load_server_metadata() and get token_endpoint
token_endpoint = (
"http://localhost:8180/realms/daewy/protocol/openid-connect/token"
)
auth_method = PrivateKeyJWT(token_endpoint)
client_kwargs.update(
{
"client_auth_methods": [auth_method],
"token_endpoint_auth_method": auth_method.name,
}
)

oauth.register(
name="keycloak",
Expand Down

0 comments on commit ae05cfb

Please sign in to comment.