Skip to content

Commit

Permalink
Breakout into files
Browse files Browse the repository at this point in the history
  • Loading branch information
alukach committed Aug 19, 2024
1 parent aa30f7d commit 78b75a0
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 36 deletions.
4 changes: 4 additions & 0 deletions runtimes/eoapi/auth/eoapi/auth/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .auth import OidcAuth # noqa
from .config import AuthSettings # noqa

__version__ = "0.1.0"
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,17 @@
import logging
import urllib.request
from dataclasses import dataclass, field
from typing import Annotated, Any, Callable, Dict, Optional, Sequence, TypedDict
from typing import Annotated, Any, Callable, Dict, Optional, Sequence

import jwt
from fastapi import HTTPException, Security, routing, security, status
from fastapi.dependencies.utils import get_parameterless_sub_dependant
from fastapi.security.base import SecurityBase
from pydantic import AnyHttpUrl
from pydantic_settings import BaseSettings

logger = logging.getLogger(__name__)


__version__ = "0.1.0"


class Scope(TypedDict, total=False):
"""More strict version of Starlette's Scope."""

# https://github.com/encode/starlette/blob/6af5c515e0a896cbf3f86ee043b88f6c24200bcf/starlette/types.py#L3
path: str
method: str
type: Optional[str]

from .types import OidcFetchError

class AuthSettings(BaseSettings):
# Swagger UI config for Authorization Code Flow
client_id: str = ""
use_pkce: bool = True
openid_configuration_url: Optional[AnyHttpUrl] = None
openid_configuration_internal_url: Optional[AnyHttpUrl] = None

allowed_jwt_audiences: Optional[Sequence[str]] = []

public_reads: bool = True

model_config = {
"env_prefix": "EOAPI_AUTH_",
"env_file": ".env",
"extra": "allow",
}
logger = logging.getLogger(__name__)


@dataclass
Expand Down Expand Up @@ -172,7 +143,3 @@ def apply_auth_dependencies(
# https://github.com/tiangolo/fastapi/blob/58ab733f19846b4875c5b79bfb1f4d1cb7f4823f/fastapi/applications.py#L337-L360
# https://github.com/tiangolo/fastapi/blob/58ab733f19846b4875c5b79bfb1f4d1cb7f4823f/fastapi/routing.py#L677-L678
api_route.dependencies.extend([depends])


class OidcFetchError(Exception):
pass
22 changes: 22 additions & 0 deletions runtimes/eoapi/auth/eoapi/auth/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from typing import Optional, Sequence

from pydantic import AnyHttpUrl
from pydantic_settings import BaseSettings


class AuthSettings(BaseSettings):
# Swagger UI config for Authorization Code Flow
client_id: str = ""
use_pkce: bool = True
openid_configuration_url: Optional[AnyHttpUrl] = None
openid_configuration_internal_url: Optional[AnyHttpUrl] = None

allowed_jwt_audiences: Optional[Sequence[str]] = []

public_reads: bool = True

model_config = {
"env_prefix": "EOAPI_AUTH_",
"env_file": ".env",
"extra": "allow",
}
14 changes: 14 additions & 0 deletions runtimes/eoapi/auth/eoapi/auth/types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from typing import Optional, TypedDict


class OidcFetchError(Exception):
pass


class Scope(TypedDict, total=False):
"""More strict version of Starlette's Scope."""

# https://github.com/encode/starlette/blob/6af5c515e0a896cbf3f86ee043b88f6c24200bcf/starlette/types.py#L3
path: str
method: str
type: Optional[str]

0 comments on commit 78b75a0

Please sign in to comment.