presentation.routers.api.v1.providers¶
src.presentation.routers.api.v1.providers
¶
Providers resource handlers.
Handler functions for provider connection endpoints. Routes are registered via ROUTE_REGISTRY in routes/registry.py.
Handlers
list_providers - List all connections for user get_provider_connection - Get connection details initiate_connection - Initiate OAuth connection oauth_callback - Handle OAuth callback update_provider - Update connection (alias) disconnect_provider - Disconnect provider refresh_provider_tokens - Refresh provider tokens
Reference
- docs/architecture/api-design-patterns.md
- docs/architecture/provider-oauth-architecture.md
- docs/architecture/error-handling-architecture.md
Classes¶
Functions¶
list_providers
async
¶
list_providers(
request: Request,
current_user: AuthenticatedUser,
active_only: Annotated[
bool,
Query(description="Only return active connections"),
] = False,
handler: ListProviderConnectionsHandler = Depends(
handler_factory(ListProviderConnectionsHandler)
),
) -> ProviderConnectionListResponse | JSONResponse
List all provider connections for user.
GET /api/v1/providers → 200 OK
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
FastAPI request object. |
required |
current_user
|
AuthenticatedUser
|
Authenticated user (from JWT). |
required |
active_only
|
Annotated[bool, Query(description='Only return active connections')]
|
Filter to only active connections. |
False
|
handler
|
ListProviderConnectionsHandler
|
List connections handler (injected). |
Depends(handler_factory(ListProviderConnectionsHandler))
|
Returns:
| Type | Description |
|---|---|
ProviderConnectionListResponse | JSONResponse
|
ProviderConnectionListResponse with list of connections. |
ProviderConnectionListResponse | JSONResponse
|
JSONResponse with RFC 9457 error on failure. |
Source code in src/presentation/routers/api/v1/providers.py
get_provider_connection
async
¶
get_provider_connection(
request: Request,
current_user: AuthenticatedUser,
connection_id: Annotated[
UUID, Path(description="Connection UUID")
],
handler: GetProviderConnectionHandler = Depends(
handler_factory(GetProviderConnectionHandler)
),
) -> ProviderConnectionResponse | JSONResponse
Get a specific provider connection.
GET /api/v1/providers/{id} → 200 OK
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
FastAPI request object. |
required |
current_user
|
AuthenticatedUser
|
Authenticated user (from JWT). |
required |
connection_id
|
Annotated[UUID, Path(description='Connection UUID')]
|
Connection UUID. |
required |
handler
|
GetProviderConnectionHandler
|
Get connection handler (injected). |
Depends(handler_factory(GetProviderConnectionHandler))
|
Returns:
| Type | Description |
|---|---|
ProviderConnectionResponse | JSONResponse
|
ProviderConnectionResponse with connection details. |
ProviderConnectionResponse | JSONResponse
|
JSONResponse with RFC 9457 error on failure. |
Source code in src/presentation/routers/api/v1/providers.py
initiate_connection
async
¶
initiate_connection(
request: Request,
current_user: AuthenticatedUser,
data: ConnectProviderRequest,
cache: CacheProtocol = Depends(get_cache),
) -> AuthorizationUrlResponse | JSONResponse
Initiate OAuth connection to a provider.
POST /api/v1/providers → 201 Created
Generates OAuth state, stores it in cache, and returns authorization URL. User should be redirected to this URL to complete OAuth consent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
FastAPI request object. |
required |
current_user
|
AuthenticatedUser
|
Authenticated user (from JWT). |
required |
data
|
ConnectProviderRequest
|
Connection request with provider_slug and optional alias. |
required |
cache
|
CacheProtocol
|
Cache for storing OAuth state (injected). |
Depends(get_cache)
|
Returns:
| Type | Description |
|---|---|
AuthorizationUrlResponse | JSONResponse
|
AuthorizationUrlResponse with authorization URL and state. |
AuthorizationUrlResponse | JSONResponse
|
JSONResponse with RFC 9457 error on failure. |
Source code in src/presentation/routers/api/v1/providers.py
oauth_callback
async
¶
oauth_callback(
request: Request,
code: Annotated[
str,
Query(
description="Authorization code from provider"
),
],
state: Annotated[
str, Query(description="CSRF state token")
],
cache: CacheProtocol = Depends(get_cache),
encryption: EncryptionService = Depends(
get_encryption_service
),
connect_handler: ConnectProviderHandler = Depends(
handler_factory(ConnectProviderHandler)
),
) -> ProviderConnectionResponse | JSONResponse
Complete OAuth callback and create connection.
POST /api/v1/providers/callback?code=xxx&state=yyy → 201 Created
Validates state, exchanges code for tokens, encrypts credentials, and creates provider connection record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
FastAPI request object. |
required |
code
|
Annotated[str, Query(description='Authorization code from provider')]
|
Authorization code from OAuth redirect. |
required |
state
|
Annotated[str, Query(description='CSRF state token')]
|
State token from OAuth redirect. |
required |
cache
|
CacheProtocol
|
Cache for retrieving stored state (injected). |
Depends(get_cache)
|
encryption
|
EncryptionService
|
Encryption service for credentials (injected). |
Depends(get_encryption_service)
|
connect_handler
|
ConnectProviderHandler
|
Connection handler (injected). |
Depends(handler_factory(ConnectProviderHandler))
|
Returns:
| Type | Description |
|---|---|
ProviderConnectionResponse | JSONResponse
|
ProviderConnectionResponse with new connection details. |
ProviderConnectionResponse | JSONResponse
|
JSONResponse with RFC 9457 error on failure. |
Source code in src/presentation/routers/api/v1/providers.py
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 | |
update_provider
async
¶
update_provider(
request: Request,
current_user: AuthenticatedUser,
connection_id: Annotated[
UUID, Path(description="Connection UUID")
],
data: UpdateProviderConnectionRequest,
get_handler: GetProviderConnectionHandler = Depends(
handler_factory(GetProviderConnectionHandler)
),
) -> ProviderConnectionResponse | JSONResponse
Update a provider connection.
PATCH /api/v1/providers/{id} → 200 OK
Currently only supports updating the alias. Future versions may support additional fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
FastAPI request object. |
required |
current_user
|
AuthenticatedUser
|
Authenticated user (from JWT). |
required |
connection_id
|
Annotated[UUID, Path(description='Connection UUID')]
|
Connection UUID. |
required |
data
|
UpdateProviderConnectionRequest
|
Update request with new alias. |
required |
get_handler
|
GetProviderConnectionHandler
|
Get handler for returning updated connection. |
Depends(handler_factory(GetProviderConnectionHandler))
|
Returns:
| Type | Description |
|---|---|
ProviderConnectionResponse | JSONResponse
|
ProviderConnectionResponse with updated connection. |
ProviderConnectionResponse | JSONResponse
|
JSONResponse with RFC 9457 error on failure. |
Note
Full update implementation requires repository update method. For Phase 5, this is a simplified implementation.
Source code in src/presentation/routers/api/v1/providers.py
disconnect_provider
async
¶
disconnect_provider(
request: Request,
current_user: AuthenticatedUser,
connection_id: Annotated[
UUID, Path(description="Connection UUID")
],
handler: DisconnectProviderHandler = Depends(
handler_factory(DisconnectProviderHandler)
),
) -> Response | JSONResponse
Disconnect a provider connection.
DELETE /api/v1/providers/{id} → 204 No Content
Transitions connection to DISCONNECTED status and clears credentials. The connection record is kept for audit purposes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
FastAPI request object. |
required |
current_user
|
AuthenticatedUser
|
Authenticated user (from JWT). |
required |
connection_id
|
Annotated[UUID, Path(description='Connection UUID')]
|
Connection UUID. |
required |
handler
|
DisconnectProviderHandler
|
Disconnect handler (injected). |
Depends(handler_factory(DisconnectProviderHandler))
|
Returns:
| Type | Description |
|---|---|
Response | JSONResponse
|
Response (204 No Content) on success. |
Response | JSONResponse
|
JSONResponse with RFC 9457 error on failure. |
Source code in src/presentation/routers/api/v1/providers.py
refresh_provider_tokens
async
¶
refresh_provider_tokens(
request: Request,
current_user: AuthenticatedUser,
connection_id: Annotated[
UUID, Path(description="Connection UUID")
],
data: RefreshProviderTokensRequest | None = None,
get_handler: GetProviderConnectionHandler = Depends(
handler_factory(GetProviderConnectionHandler)
),
refresh_handler: RefreshProviderTokensHandler = Depends(
handler_factory(RefreshProviderTokensHandler)
),
encryption: EncryptionService = Depends(
get_encryption_service
),
) -> TokenRefreshResponse | JSONResponse
Refresh OAuth tokens for a provider connection.
POST /api/v1/providers/{id}/token-refreshes → 201 Created
Decrypts current refresh token, calls provider to refresh, encrypts new tokens, and updates connection credentials.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
FastAPI request object. |
required |
current_user
|
AuthenticatedUser
|
Authenticated user (from JWT). |
required |
connection_id
|
Annotated[UUID, Path(description='Connection UUID')]
|
Connection UUID. |
required |
data
|
RefreshProviderTokensRequest | None
|
Optional refresh request with force flag. |
None
|
get_handler
|
GetProviderConnectionHandler
|
Get handler for fetching connection. |
Depends(handler_factory(GetProviderConnectionHandler))
|
refresh_handler
|
RefreshProviderTokensHandler
|
Token refresh handler (injected). |
Depends(handler_factory(RefreshProviderTokensHandler))
|
encryption
|
EncryptionService
|
Encryption service for credentials. |
Depends(get_encryption_service)
|
Returns:
| Type | Description |
|---|---|
TokenRefreshResponse | JSONResponse
|
TokenRefreshResponse with refresh result. |
TokenRefreshResponse | JSONResponse
|
JSONResponse with RFC 9457 error on failure. |
Source code in src/presentation/routers/api/v1/providers.py
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 | |