Skip to content

Commit

Permalink
Add JWKS and logout methods (#265)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
PaulAsjes authored May 17, 2024
1 parent 759e030 commit 6409314
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/test_user_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,21 @@ def test_authenticate_with_refresh_token(
assert request["json"]["client_secret"] == "sk_test"
assert request["json"]["grant_type"] == "refresh_token"

def test_get_jwks_url(self):
expected = "%s/sso/jwks/%s" % (workos.base_api_url, workos.client_id)
result = self.user_management.get_jwks_url()

assert expected == result

def test_get_logout_url(self):
expected = "%s/user_management/sessions/logout?session_id=%s" % (
workos.base_api_url,
"session_123",
)
result = self.user_management.get_logout_url("session_123")

assert expected == result

def test_send_password_reset_email(self, capture_and_mock_request):
email = "[email protected]"
password_reset_url = "https://foo-corp.com/reset-password"
Expand Down
25 changes: 25 additions & 0 deletions workos/user_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,30 @@ def authenticate_with_refresh_token(
response
).to_dict()

def get_jwks_url(self):
"""Get the public key that is used for verifying access tokens.
Returns:
(str): The public JWKS URL.
"""

return "%s/sso/jwks/%s" % (workos.base_api_url, workos.client_id)

def get_logout_url(self, session_id):
"""Get the URL for ending the session and redirecting the user
Kwargs:
session_id (str): The ID of the user's session
Returns:
(str): URL to redirect the user to to end the session.
"""

return "%s/user_management/sessions/logout?session_id=%s" % (
workos.base_api_url,
session_id,
)

def send_password_reset_email(
self,
email,
Expand Down Expand Up @@ -1001,6 +1025,7 @@ def enroll_auth_factor(
] = WorkOSAuthenticationFactorTotp.construct_from_response(
response["authentication_factor"]
).to_dict()

factor_and_challenge[
"authentication_challenge"
] = WorkOSChallenge.construct_from_response(
Expand Down

0 comments on commit 6409314

Please sign in to comment.