Skip to content
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

doc: enhanced the auth route documentation #244

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 16 additions & 2 deletions API/auth/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@

from src.app import Users

from src.validation.models import (
LoginResponse,
CallbackResponse
)

from . import AuthUser, admin_required, login_required, osm_auth, staff_required

router = APIRouter(prefix="/auth", tags=["Auth"])


@router.get("/login/")
@router.get("/login/", response_model=LoginResponse)
def login_url(request: Request):
"""Generate Login URL for authentication using OAuth2 Application registered with OpenStreetMap.
Click on the download url returned to get access_token.
Expand All @@ -25,13 +30,16 @@ def login_url(request: Request):
return login_url


@router.get("/callback/")
@router.get("/callback/", response_model=CallbackResponse)
def callback(request: Request):
"""Performs token exchange between OpenStreetMap and Raw Data API

Core will use Oauth secret key from configuration while deserializing token,
provides access token that can be used for authorized endpoints.

This endpoint handles the OAuth callback after the user has authorized the
application by visiting the link generated by the by the `/auth/login/` route

Parameters: None

Returns:
Expand Down Expand Up @@ -81,6 +89,7 @@ async def create_user(params: User, user_data: AuthUser = Depends(admin_required

Raises:
- HTTPException: If the user creation fails.
- HTTPException(403): User is not an admin (Forbidden).
"""
auth = Users()
return auth.create_user(params.osm_id, params.role)
Expand All @@ -104,6 +113,7 @@ async def read_user(osm_id: int, user_data: AuthUser = Depends(staff_required)):

Raises:
- HTTPException: If the user with the given osm_id is not found.
- HTTPException(403): User is not a staff (Forbidden).
"""
auth = Users()

Expand Down Expand Up @@ -149,6 +159,7 @@ async def delete_user(osm_id: int, user_data: AuthUser = Depends(admin_required)

Raises:
- HTTPException: If the user with the given osm_id is not found.
- HTTPException(403): User is not an admin (Forbidden).
"""
auth = Users()
return auth.delete_user(osm_id)
Expand All @@ -168,6 +179,9 @@ async def read_users(

Returns:
- List[Dict[str, Any]]: A list of dictionaries containing user information.

Raises:
- HTTPException(403): User is not a staff (Forbidden).
"""
auth = Users()
return auth.read_users(skip, limit)
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ USER appuser
# API and source code, changes here don't invalidate previous layers , You can overwrite this block with -v

# Copy config.txt if you have your configuration setup in config
# COPY config.txt .
COPY config.txt ./config.txt
COPY README.md .
COPY setup.py .
COPY pyproject.toml .
Expand Down
2 changes: 1 addition & 1 deletion docker-compose-config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ OSM_CLIENT_SECRET=
OSM_URL=https://www.openstreetmap.org
OSM_PERMISSION_SCOPE=read_prefs
LOGIN_REDIRECT_URI=http://127.0.0.1:8000/v1/auth/callback
APP_SECRET_KEY=replace_this_with_your_trusted_secret_key
APP_SECRET_KEY=
5 changes: 5 additions & 0 deletions src/validation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@ class StatusResponse(BaseModel):
class Config:
json_schema_extra = {"example": {"lastUpdated": "2022-06-27 19:59:24+05:45"}}

class LoginResponse(BaseModel):
login_url: str = Field(alias="login_url")

class CallbackResponse(BaseModel):
access_token: str = Field(alias="access_token")

class StatsRequestParams(BaseModel, GeometryValidatorMixin):
iso3: Optional[str] = Field(
Expand Down