Skip to content

Commit

Permalink
chore: removes unused helper methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ctran88 committed Jan 2, 2025
1 parent e1d7d74 commit 23a00b2
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 64 deletions.
40 changes: 0 additions & 40 deletions passageidentity/helper.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,10 @@
"""Provides helper functions for interacting with the Passage Identity API."""

import re
from http import HTTPStatus

from requests.sessions import Request

from passageidentity import requests
from passageidentity.errors import PassageError

BEARER_PATTERN = r"Bearer ([^\s,]+)"


def extract_token(auth_header: str) -> str:
"""Extract the JWT from an Authorization header."""
expression = re.escape(BEARER_PATTERN)
match = re.search(expression, auth_header)

if match:
return match.group(1)

msg = "No Passage authorization header."
raise PassageError(msg)


def get_auth_token_from_request(request: Request, auth_strategy: int) -> str:
"""Get the auth token from a request.
Checks the Authorization header first, then the psg_auth_token cookie.
"""
if auth_strategy == 2: # noqa: PLR2004
auth_header = request.headers["Authorization"]
expression = re.escape(BEARER_PATTERN)
match = re.search(expression, auth_header)

if match:
return match.group(1)

msg = "No Passage authorization header."
raise PassageError(msg)

if "psg_auth_token" not in request.cookies:
msg = "No Passage authentication token."
raise PassageError(msg)

return request.cookies["psg_auth_token"]


def fetch_app(app_id: str) -> dict:
"""Fetch the public key for the given app id from Passage."""
Expand Down
24 changes: 0 additions & 24 deletions passageidentity/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from __future__ import annotations

import json
from importlib import metadata

import requests
Expand All @@ -22,26 +21,3 @@ def get_headers(api_key: str | None = None) -> dict[str, str]:
def get(url: str, api_key: str | None = None) -> requests.Response:
"""Send a GET request with API key in Authorization header if provided."""
return requests.get(url, headers=get_headers(api_key)) # noqa: S113


def post(url: str, api_key: str | None = None, data: dict | None = None) -> requests.Response:
"""Send a POST request with API key in Authorization header if provided, and the JSON-encoded data in the body."""
return requests.post( # noqa: S113
url,
headers=get_headers(api_key),
data=json.dumps(data) if data else None,
)


def patch(url: str, api_key: str | None = None, data: dict | None = None) -> requests.Response:
"""Send a PATCH request with API key in Authorization header if provided, and the JSON-encoded data in the body."""
return requests.patch( # noqa: S113
url,
headers=get_headers(api_key),
data=json.dumps(data) if data else None,
)


def delete(url: str, api_key: str | None = None) -> requests.Response:
"""Send a DELETE request with API key in Authorization header if provided."""
return requests.delete(url, headers=get_headers(api_key)) # noqa: S113

0 comments on commit 23a00b2

Please sign in to comment.