Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4c206d6

Browse files
committedDec 23, 2024·
chore: removes unused helper methods
1 parent d0793cc commit 4c206d6

File tree

2 files changed

+0
-64
lines changed

2 files changed

+0
-64
lines changed
 

‎passageidentity/helper.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,10 @@
11
"""Provides helper functions for interacting with the Passage Identity API."""
22

3-
import re
43
from http import HTTPStatus
54

6-
from requests.sessions import Request
7-
85
from passageidentity import requests
96
from passageidentity.errors import PassageError
107

11-
BEARER_PATTERN = r"Bearer ([^\s,]+)"
12-
13-
14-
def extract_token(auth_header: str) -> str:
15-
"""Extract the JWT from an Authorization header."""
16-
expression = re.escape(BEARER_PATTERN)
17-
match = re.search(expression, auth_header)
18-
19-
if match:
20-
return match.group(1)
21-
22-
msg = "No Passage authorization header."
23-
raise PassageError(msg)
24-
25-
26-
def get_auth_token_from_request(request: Request, auth_strategy: int) -> str:
27-
"""Get the auth token from a request.
28-
29-
Checks the Authorization header first, then the psg_auth_token cookie.
30-
"""
31-
if auth_strategy == 2: # noqa: PLR2004
32-
auth_header = request.headers["Authorization"]
33-
expression = re.escape(BEARER_PATTERN)
34-
match = re.search(expression, auth_header)
35-
36-
if match:
37-
return match.group(1)
38-
39-
msg = "No Passage authorization header."
40-
raise PassageError(msg)
41-
42-
if "psg_auth_token" not in request.cookies:
43-
msg = "No Passage authentication token."
44-
raise PassageError(msg)
45-
46-
return request.cookies["psg_auth_token"]
47-
488

499
def fetch_app(app_id: str) -> dict:
5010
"""Fetch the public key for the given app id from Passage."""

‎passageidentity/requests.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from __future__ import annotations
44

5-
import json
65
from importlib import metadata
76

87
import requests
@@ -22,26 +21,3 @@ def get_headers(api_key: str | None = None) -> dict[str, str]:
2221
def get(url: str, api_key: str | None = None) -> requests.Response:
2322
"""Send a GET request with API key in Authorization header if provided."""
2423
return requests.get(url, headers=get_headers(api_key)) # noqa: S113
25-
26-
27-
def post(url: str, api_key: str | None = None, data: dict | None = None) -> requests.Response:
28-
"""Send a POST request with API key in Authorization header if provided, and the JSON-encoded data in the body."""
29-
return requests.post( # noqa: S113
30-
url,
31-
headers=get_headers(api_key),
32-
data=json.dumps(data) if data else None,
33-
)
34-
35-
36-
def patch(url: str, api_key: str | None = None, data: dict | None = None) -> requests.Response:
37-
"""Send a PATCH request with API key in Authorization header if provided, and the JSON-encoded data in the body."""
38-
return requests.patch( # noqa: S113
39-
url,
40-
headers=get_headers(api_key),
41-
data=json.dumps(data) if data else None,
42-
)
43-
44-
45-
def delete(url: str, api_key: str | None = None) -> requests.Response:
46-
"""Send a DELETE request with API key in Authorization header if provided."""
47-
return requests.delete(url, headers=get_headers(api_key)) # noqa: S113

0 commit comments

Comments
 (0)
Please sign in to comment.