为eoAPI提供身份验证和授权助手
项目描述
eoAPI Auth Utils
为eoAPI应用程序提供身份验证和授权模式助手。
使用方法
安装
pip install eoapi.auth-utils
集成
在您的eoAPI应用程序中
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])
开发
发布
发布通过CICD工作流程管理,如Python打包用户指南中所述。要创建新版本
- 根据适当的语义版本控制约定更新
eoapi/auth_utils/__init__.py
中的版本号。 - 将带标签的提交推送到
main
,标签与包的新版本号匹配。
[!注意]
此软件包使用Github的自动生成的发布说明。如果合适,可以稍后对其进行补充。
项目详情
下载文件
下载适用于您平台的自定义文件。如果您不确定选择哪个,请了解有关安装软件包的更多信息。
源分布
eoapi.auth-utils-0.4.0.tar.gz (5.2 kB 查看哈希值)