Authentication & authorization helpers for eoAPI
Project description
eoAPI Auth Utils
Helpers for authentication & authorization patterns for eoAPI applications.
Usage
Installation
pip install eoapi.auth-utils
Integration
In your eoAPI application:
from eoapi.auth_utils import AuthSettings, OpenIdConnectAuth
from fastapi import FastAPI
from fastapi.routing import APIRoute
from stac_fastapi.api.app import StacApi
auth_settings = AuthSettings(_env_prefix="AUTH_")
api = StacApi(
app=FastAPI(
# ...
swagger_ui_init_oauth={
"clientId": auth_settings.client_id,
"usePkceWithAuthorizationCodeGrant": auth_settings.use_pkce,
},
),
# ...
)
if auth_settings.openid_configuration_url:
oidc_auth = OpenIdConnectAuth.from_settings(auth_settings)
# Implement your custom app-specific auth logic here...
restricted_routes = {
"/collections": ("POST", "stac:collection:create"),
"/collections/{collection_id}": ("PUT", "stac:collection:update"),
"/collections/{collection_id}": ("DELETE", "stac:collection:delete"),
"/collections/{collection_id}/items": ("POST", "stac:item:create"),
"/collections/{collection_id}/items/{item_id}": ("PUT", "stac:item:update"),
"/collections/{collection_id}/items/{item_id}": ("DELETE", "stac:item:delete"),
}
api_routes = {
route.path: route for route in api.app.routes if isinstance(route, APIRoute)
}
for endpoint, (method, scope) in restricted_routes.items():
route = api_routes.get(endpoint)
if route and method in route.methods:
oidc_auth.apply_auth_dependencies(route, required_token_scopes=[scope])
Development
Releases
Releases are managed via CICD workflow, as described in the Python Packaging User Guide. To create a new release:
- Update the version in
eoapi/auth_utils/__init__.py
following appropriate Semantic Versioning convention. - Push a tagged commit to
main
, with the tag matching the package's new version number.
[!NOTE]
This package makes use of Github's automatically generated release notes. These can be later augmented if one sees fit.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file eoapi.auth-utils-0.4.0.tar.gz
.
File metadata
- Download URL: eoapi.auth-utils-0.4.0.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 621abe10eed293a5a2bc158a62d25311aa4dfced0bbf4a2c6ee8aefc443bb3aa |
|
MD5 | 927fae7e76b09a40789f06cdad63f57b |
|
BLAKE2b-256 | 52cc185f9d7c42a124b0405cf9ea4def38659a13cf47d28a657b49b7407cebfb |
File details
Details for the file eoapi.auth_utils-0.4.0-py3-none-any.whl
.
File metadata
- Download URL: eoapi.auth_utils-0.4.0-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa55e5c20012796603bb09740b3689ffc31b91df470a43c7765ae37e6c68f276 |
|
MD5 | b43a9c5f7b6b568228613666dd37a1ae |
|
BLAKE2b-256 | 7eac877ebdeb4ca4d16d34936a3a72cb9544271adaf64760a243a81becc037ab |