-
Notifications
You must be signed in to change notification settings - Fork 183
Feature/adding sessions #672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
victorhos
wants to merge
18
commits into
auth0:master
Choose a base branch
from
victorhos:feature/adding-sessions
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
d70cecc
feat: adding sessions endpoints
eeee9b2
feat: add sessions in users and update doc
0a4b7a1
chore(pre-commit): update flake8 to 7
victorhos da1cf2b
Updates for CIBA with email
adamjmcgrath 6adb025
Remove erroneous print
adamjmcgrath f04ac1b
chore: fix workflow syntax errors and update dependencies (#724)
kishore7snehil 6cf74ec
Release 4.11.0 (#725)
kishore7snehil 1e09057
Add headers to Auth0Error
adamjmcgrath 47238d9
fix: add missing indentation for Python configuration step
kishore7snehil bfd7587
Updates per PR feedback
adamjmcgrath a95935c
Release 4.12.0
adamjmcgrath fdf71f2
fix(backchannel): expose headers on `slow_down` errors (HTTP 429s)
pmalouin ddbf0b5
Release 4.13.0 (#745)
adamjmcgrath d803e7f
chore(deps): bump snyk/actions from 0.4.0 to 1.0.0 (#750)
dependabot[bot] b59349d
chore(deps): bump github/codeql-action from 3 to 4 (#751)
dependabot[bot] 729c676
feat: add Claude Code PR Review workflow (#752)
kishore7snehil da856f3
feat: Add Ask DeepWiki badge
arpit-jn b143824
Merge branch 'master' into feature/adding-sessions
kishore7snehil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| from typing import Any | ||
|
|
||
| from auth0.rest import RestClient | ||
| from auth0.rest import RestClientOptions | ||
| from auth0.types import TimeoutType | ||
|
|
||
|
|
||
| class Sessions: | ||
| """Auth0 users endpoints | ||
|
|
||
| Args: | ||
| domain (str): Your Auth0 domain, e.g: 'username.auth0.com' | ||
|
|
||
| token (str): Management API v2 Token | ||
|
|
||
| telemetry (bool, optional): Enable or disable Telemetry | ||
| (defaults to True) | ||
|
|
||
| timeout (float or tuple, optional): Change the requests | ||
| connect and read timeout. Pass a tuple to specify | ||
| both values separately or a float to set both to it. | ||
| (defaults to 5.0 for both) | ||
|
|
||
| protocol (str, optional): Protocol to use when making requests. | ||
| (defaults to "https") | ||
|
|
||
| rest_options (RestClientOptions): Pass an instance of | ||
| RestClientOptions to configure additional RestClient | ||
| options, such as rate-limit retries. | ||
| (defaults to None) | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| domain: str, | ||
| token: str, | ||
| telemetry: bool = True, | ||
| timeout: TimeoutType = 5.0, | ||
| protocol: str = "https", | ||
| rest_options: RestClientOptions | None = None, | ||
| ) -> None: | ||
| self.domain = domain | ||
| self.protocol = protocol | ||
| self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout, options=rest_options) | ||
|
|
||
| def _url(self, id: str | None = None) -> str: | ||
| url = f"{self.protocol}://{self.domain}/api/v2/sessions" | ||
| if id is not None: | ||
| return f"{url}/{id}" | ||
| return url | ||
|
|
||
| def get(self, id: str) -> dict[str, Any]: | ||
| """Get a session. | ||
|
|
||
| Args: | ||
| id (str): The id of the session to retrieve. | ||
|
|
||
| See: https://auth0.com/docs/api/management/v2#!/Sessions/get-session | ||
| """ | ||
|
|
||
| return self.client.get(self._url(id)) | ||
|
|
||
| def delete(self, id: str) -> None: | ||
| """Delete a session. | ||
|
|
||
| Args: | ||
| id (str): The id of the session to delete. | ||
|
|
||
| See: https://auth0.com/docs/api/management/v2#!/Sessions/delete-session | ||
| """ | ||
|
|
||
| return self.client.delete(self._url(id)) | ||
|
|
||
| def revoke(self, id: str) -> None: | ||
| """Revokes a session by ID and all associated refresh tokens.. | ||
|
|
||
| Args: | ||
| id (str): The id of the session to revoke. | ||
|
|
||
| See: https://auth0.com/docs/api/management/v2#!/Sessions/revoke-session | ||
| """ | ||
|
|
||
| url = self._url(f"{id}/sessions") | ||
| return self.client.post(url) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import unittest | ||
| from unittest import mock | ||
|
|
||
| from ...management.sessions import Sessions | ||
|
|
||
|
|
||
| class TestSessions(unittest.TestCase): | ||
| def test_init_with_optionals(self): | ||
| t = Sessions(domain="domain", token="jwttoken", telemetry=False, timeout=(10, 2)) | ||
| self.assertEqual(t.client.options.timeout, (10, 2)) | ||
| telemetry_header = t.client.base_headers.get("Auth0-Client", None) | ||
| self.assertEqual(telemetry_header, None) | ||
|
|
||
| @mock.patch("auth0.management.sessions.RestClient") | ||
| def test_get(self, mock_rc): | ||
| mock_instance = mock_rc.return_value | ||
|
|
||
| u = Sessions(domain="domain", token="jwttoken") | ||
| u.get("session_id") | ||
|
|
||
| mock_instance.get.assert_called_with( | ||
| "https://domain/api/v2/sessions/session_id" | ||
| ) | ||
|
|
||
| @mock.patch("auth0.management.sessions.RestClient") | ||
| def test_delete(self, mock_rc): | ||
| mock_instance = mock_rc.return_value | ||
|
|
||
| u = Sessions(domain="domain", token="jwttoken") | ||
| u.delete("session_id") | ||
|
|
||
| mock_instance.delete.assert_called_with( | ||
| "https://domain/api/v2/sessions/session_id" | ||
| ) | ||
|
|
||
| @mock.patch("auth0.management.sessions.RestClient") | ||
| def test_revoke(self, mock_rc): | ||
| mock_instance = mock_rc.return_value | ||
|
|
||
| u = Sessions(domain="domain", token="jwttoken") | ||
| u.revoke("session_id") | ||
|
|
||
| mock_instance.post.assert_called_with( | ||
| "https://domain/api/v2/sessions/session_id/sessions" | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.