Skip to content

Commit ae05cfb

Browse files
committed
Refactor
1 parent 4050978 commit ae05cfb

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

keycloak/oauth.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class KeycloakOAuth2:
2525
def __init__(
2626
self,
2727
client_id: str,
28-
client_secret: str | bytes,
28+
client_secret: str | bytes | None,
2929
server_metadata_url: str,
3030
client_kwargs: dict[str, Any],
3131
base_url: str = "/",
@@ -39,24 +39,25 @@ def __init__(
3939

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

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

49-
# TODO call self.keycloak.load_server_metadata() and get token_endpoint
50-
token_endpoint = (
51-
"http://localhost:8180/realms/daewy/protocol/openid-connect/token"
52-
)
53-
auth_method = PrivateKeyJWT(token_endpoint)
54-
client_kwargs.update(
55-
{
56-
"client_auth_methods": [auth_method],
57-
"token_endpoint_auth_method": auth_method.name,
58-
}
59-
)
50+
# TODO call self.keycloak.load_server_metadata() and get token_endpoint
51+
token_endpoint = (
52+
"http://localhost:8180/realms/daewy/protocol/openid-connect/token"
53+
)
54+
auth_method = PrivateKeyJWT(token_endpoint)
55+
client_kwargs.update(
56+
{
57+
"client_auth_methods": [auth_method],
58+
"token_endpoint_auth_method": auth_method.name,
59+
}
60+
)
6061

6162
oauth.register(
6263
name="keycloak",

0 commit comments

Comments
 (0)