Skip to content

Commit eeee9b2

Browse files
Victor Silvavictorhos
authored andcommitted
feat: add sessions in users and update doc
1 parent d70cecc commit eeee9b2

File tree

5 files changed

+75
-9
lines changed

5 files changed

+75
-9
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ For more code samples on how to integrate the auth0-python SDK in your Python ap
125125
- Rules() ( `Auth0().rules` )
126126
- SelfServiceProfiles() ( `Auth0().self_service_profiles` )
127127
- Stats() ( `Auth0().stats` )
128+
- Sessions() ( `Auth0().sessions` )
128129
- Tenants() ( `Auth0().tenants` )
129130
- Tickets() ( `Auth0().tickets` )
130131
- UserBlocks() (`Auth0().user_blocks` )

auth0/management/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from .rules import Rules
2525
from .rules_configs import RulesConfigs
2626
from .self_service_profiles import SelfServiceProfiles
27+
from .sessions import Sessions
2728
from .stats import Stats
2829
from .tenants import Tenants
2930
from .tickets import Tickets
@@ -64,6 +65,7 @@
6465
"Rules",
6566
"SelfServiceProfiles",
6667
"Stats",
68+
"Sessions",
6769
"Tenants",
6870
"Tickets",
6971
"UserBlocks",

auth0/management/users.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,9 @@ def unlink_user_account(self, id: str, provider: str, user_id: str) -> Any:
348348
url = self._url(f"{id}/identities/{provider}/{user_id}")
349349
return self.client.delete(url)
350350

351-
def link_user_account(self, user_id: str, body: dict[str, Any]) -> list[dict[str, Any]]:
351+
def link_user_account(
352+
self, user_id: str, body: dict[str, Any]
353+
) -> list[dict[str, Any]]:
352354
"""Link user accounts.
353355
354356
Links the account specified in the body (secondary account) to the
@@ -580,4 +582,43 @@ def delete_tokenset_by_id(
580582
"""
581583

582584
url = self._url(f"{user_id}/federated-connections-tokensets/{tokenset_id}")
583-
return self.client.delete(url)
585+
return self.client.delete(url)
586+
587+
def delete_tokenset_by_id(
588+
self, user_id: str, tokenset_id: str
589+
) -> Any:
590+
"""Deletes an tokenset by ID.
591+
592+
Args:
593+
user_id (str): The user_id to delete an authentication method by ID for.
594+
tokenset_id (str): The tokenset_id to delete an tokenset by ID for.
595+
596+
See: https://auth0.com/docs/api/management/v2#!/Users/delete_tokenset_by_id
597+
"""
598+
599+
url = self._url(f"{user_id}/federated-connections-tokensets/{tokenset_id}")
600+
return self.client.delete(url)
601+
602+
def get_sessions(self, user_id: str) -> dict[str, Any]:
603+
"""Get all sessions details for the given user.
604+
605+
Args:
606+
user_id (str): The user_id to get all sessions for the given user for.
607+
608+
see: https://auth0.com/docs/api/management/v2#!/Users/get-sessions-for-user
609+
"""
610+
611+
url = self._url(f"{user_id}/sessions")
612+
return self.client.get(url)
613+
614+
def delete_sessions(self, user_id: str) -> dict[str, Any]:
615+
"""Delete all sessions for the given user.
616+
617+
Args:
618+
user_id (str): The user_id to delete all session for the given user for.
619+
620+
See: https://auth0.com/docs/api/management/v2#!/Users/delete-sessions-for-user
621+
"""
622+
623+
url = self._url(f"{user_id}/sessions")
624+
return self.client.delete(url)

auth0/test/management/test_sessions.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
import unittest
22
from unittest import mock
33

4-
from ...management.users import Sessions
4+
from ...management.sessions import Sessions
55

66

7-
class TestUsers(unittest.TestCase):
7+
class TestSessions(unittest.TestCase):
88
def test_init_with_optionals(self):
99
t = Sessions(domain="domain", token="jwttoken", telemetry=False, timeout=(10, 2))
1010
self.assertEqual(t.client.options.timeout, (10, 2))
1111
telemetry_header = t.client.base_headers.get("Auth0-Client", None)
1212
self.assertEqual(telemetry_header, None)
1313

14-
@mock.patch("auth0.management.users.RestClient")
14+
@mock.patch("auth0.management.sessions.RestClient")
1515
def test_get(self, mock_rc):
1616
mock_instance = mock_rc.return_value
1717

1818
u = Sessions(domain="domain", token="jwttoken")
19-
u.get("user_id")
19+
u.get("session_id")
2020

2121
mock_instance.get.assert_called_with(
2222
"https://domain/api/v2/sessions/session_id"
2323
)
2424

25-
@mock.patch("auth0.management.users.RestClient")
25+
@mock.patch("auth0.management.sessions.RestClient")
2626
def test_delete(self, mock_rc):
2727
mock_instance = mock_rc.return_value
2828

@@ -33,7 +33,7 @@ def test_delete(self, mock_rc):
3333
"https://domain/api/v2/sessions/session_id"
3434
)
3535

36-
@mock.patch("auth0.management.users.RestClient")
36+
@mock.patch("auth0.management.sessions.RestClient")
3737
def test_revoke(self, mock_rc):
3838
mock_instance = mock_rc.return_value
3939

auth0/test/management/test_users.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,4 +435,26 @@ def test_delete_tokenset_by_id(self, mock_rc):
435435

436436
mock_instance.delete.assert_called_with(
437437
"https://domain/api/v2/users/user_id/federated-connections-tokensets/tokenset_id"
438-
)
438+
)
439+
440+
@mock.patch("auth0.management.users.RestClient")
441+
def test_get_sessions_by_user(self, mock_rc):
442+
mock_instance = mock_rc.return_value
443+
444+
u = Users(domain="domain", token="jwttoken")
445+
u.get_sessions("user_id")
446+
447+
mock_instance.get.assert_called_with(
448+
"https://domain/api/v2/users/user_id/sessions"
449+
)
450+
451+
@mock.patch("auth0.management.users.RestClient")
452+
def test_delete_sessions_by_user(self, mock_rc):
453+
mock_instance = mock_rc.return_value
454+
455+
u = Users(domain="domain", token="jwttoken")
456+
u.delete_sessions("user_id")
457+
458+
mock_instance.delete.assert_called_with(
459+
"https://domain/api/v2/users/user_id/sessions"
460+
)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy