Skip to content

Commit 6409314

Browse files
authored
Add JWKS and logout methods (#265)
* Add jwks method * Add logout method * ran black * I'm getting mixed messages here black * Ran black again, this time with the same version as CI
1 parent 759e030 commit 6409314

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

tests/test_user_management.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,21 @@ def test_authenticate_with_refresh_token(
794794
assert request["json"]["client_secret"] == "sk_test"
795795
assert request["json"]["grant_type"] == "refresh_token"
796796

797+
def test_get_jwks_url(self):
798+
expected = "%s/sso/jwks/%s" % (workos.base_api_url, workos.client_id)
799+
result = self.user_management.get_jwks_url()
800+
801+
assert expected == result
802+
803+
def test_get_logout_url(self):
804+
expected = "%s/user_management/sessions/logout?session_id=%s" % (
805+
workos.base_api_url,
806+
"session_123",
807+
)
808+
result = self.user_management.get_logout_url("session_123")
809+
810+
assert expected == result
811+
797812
def test_send_password_reset_email(self, capture_and_mock_request):
798813
799814
password_reset_url = "https://foo-corp.com/reset-password"

workos/user_management.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,30 @@ def authenticate_with_refresh_token(
761761
response
762762
).to_dict()
763763

764+
def get_jwks_url(self):
765+
"""Get the public key that is used for verifying access tokens.
766+
767+
Returns:
768+
(str): The public JWKS URL.
769+
"""
770+
771+
return "%s/sso/jwks/%s" % (workos.base_api_url, workos.client_id)
772+
773+
def get_logout_url(self, session_id):
774+
"""Get the URL for ending the session and redirecting the user
775+
776+
Kwargs:
777+
session_id (str): The ID of the user's session
778+
779+
Returns:
780+
(str): URL to redirect the user to to end the session.
781+
"""
782+
783+
return "%s/user_management/sessions/logout?session_id=%s" % (
784+
workos.base_api_url,
785+
session_id,
786+
)
787+
764788
def send_password_reset_email(
765789
self,
766790
email,
@@ -1001,6 +1025,7 @@ def enroll_auth_factor(
10011025
] = WorkOSAuthenticationFactorTotp.construct_from_response(
10021026
response["authentication_factor"]
10031027
).to_dict()
1028+
10041029
factor_and_challenge[
10051030
"authentication_challenge"
10061031
] = WorkOSChallenge.construct_from_response(

0 commit comments

Comments
 (0)