diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | python-fastapi-azure-auth.spec | 568 | ||||
-rw-r--r-- | sources | 1 |
3 files changed, 570 insertions, 0 deletions
@@ -0,0 +1 @@ +/fastapi_azure_auth-4.1.1.tar.gz diff --git a/python-fastapi-azure-auth.spec b/python-fastapi-azure-auth.spec new file mode 100644 index 0000000..73de1a1 --- /dev/null +++ b/python-fastapi-azure-auth.spec @@ -0,0 +1,568 @@ +%global _empty_manifest_terminate_build 0 +Name: python-fastapi-azure-auth +Version: 4.1.1 +Release: 1 +Summary: Easy and secure implementation of Azure AD for your FastAPI APIs +License: MIT License +URL: https://github.com/intility/fastapi-azure-auth +Source0: https://mirrors.aliyun.com/pypi/web/packages/1d/ee/d7899d93ae88bf3831f8da22b3fb5a63941eab64c92b27f9f03555930f32/fastapi_azure_auth-4.1.1.tar.gz +BuildArch: noarch + +Requires: python3-fastapi +Requires: python3-cryptography +Requires: python3-jose[cryptography] +Requires: python3-httpx + +%description +<h1 align="center"> + <img margin="0 10px 0 0" src="https://avatars.githubusercontent.com/u/35199565" width="124px"/> + <img margin="0 10px 0 0" src="https://raw.githubusercontent.com/Intility/fastapi-azure-auth/main/docs/static/img/global/fastad.png" width="124px"/><br/> + FastAPI-Azure-Auth +</h1> + +<p align="center"> + <em>Azure AD Authentication for FastAPI apps made easy.</em> +</p> +<p align="center"> + <!-- Line 1 --> + <a href="https://python.org"> + <img src="https://img.shields.io/badge/python-v3.8+-blue.svg?logo=python&logoColor=white&label=python" alt="Python version"> + </a> + <a href="https://fastapi.tiangolo.com/"> + <img src="https://img.shields.io/badge/FastAPI-0.68.0+%20-blue.svg?logo=fastapi&logoColor=white&label=fastapi" alt="FastAPI Version"> + </a> + <a href="https://pypi.org/pypi/fastapi-azure-auth"> + <img src="https://img.shields.io/pypi/v/fastapi-azure-auth.svg?logo=pypi&logoColor=white&label=pypi" alt="Package version"> + </a> + <!-- Line 2 --> + <br/> + <a href="https://codecov.io/gh/intility/fastapi-azure-auth"> + <img src="https://codecov.io/gh/intility/fastapi-azure-auth/branch/main/graph/badge.svg?token=BTFGII4GYR" alt="Codecov"> + </a> + <a href="https://github.com/pre-commit/pre-commit"> + <img src="https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white" alt="Pre-commit"> + </a> + <a href="https://github.com/psf/black"> + <img src="https://img.shields.io/badge/code%20style-black-000000.svg" alt="Black"> + </a> + <a href="http://mypy-lang.org"> + <img src="http://www.mypy-lang.org/static/mypy_badge.svg" alt="mypy"> + </a> + <a href="https://pycqa.github.io/isort/"> + <img src="https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336" alt="isort"> + </a> + <!-- Line 3 --> + <br/> + <a href="https://docs.microsoft.com/en-us/azure/active-directory/develop/single-and-multi-tenant-apps"> + <img src="https://img.shields.io/badge/Single--tenant-Supported-blue?logo=Microsoft%20Azure&logoColor=white"> + </a> + <a href="https://docs.microsoft.com/en-us/azure/active-directory/develop/single-and-multi-tenant-apps"> + <img src="https://img.shields.io/badge/Multi--tenant-Supported-blue?logo=Microsoft%20Azure&logoColor=white"> + </a> +</p> + + +## 🚀 Description + +> FastAPI is a modern, fast (high-performance), web framework for building APIs with Python, based on standard Python type hints. + +At Intility we use FastAPI for both internal (single-tenant) and customer-facing (multi-tenant) APIs. This package enables our developers (and you 😊) to create features without worrying about authentication and authorization. + +Also, [we're hiring!](https://intility.no/en/career/) + +## 📚 Resources + +The [documentation](https://intility.github.io/fastapi-azure-auth/) contains a full tutorial on how to configure Azure AD +and FastAPI for both single- and multi-tenant applications. It includes examples on how to lock down +your APIs to certain scopes, tenants, roles etc. For first time users it's strongly advised to set up your +application exactly how it's described there, and then alter it to your needs later. + +[**MIT License**](https://github.com/Intility/fastapi-azure-auth/blob/main/LICENSE) +| [**Documentation**](https://intility.github.io/fastapi-azure-auth/) +| [**GitHub**](https://github.com/snok/django-guid) + + +## ⚡ Setup + +This is a tl;dr intended to give you an idea of what this package does and how to use it. +For a more in-depth tutorial and settings reference you should read the +[documentation](https://intility.github.io/fastapi-azure-auth/). + + +#### 1. Install this library: +```bash +pip install fastapi-azure-auth +# or +poetry add fastapi-azure-auth +``` + +#### 2. Configure your FastAPI app +Include `swagger_ui_oauth2_redirect_url` and `swagger_ui_init_oauth` in your FastAPI app initialization: + +```python +# file: main.py +app = FastAPI( + ... + swagger_ui_oauth2_redirect_url='/oauth2-redirect', + swagger_ui_init_oauth={ + 'usePkceWithAuthorizationCodeGrant': True, + 'clientId': settings.OPENAPI_CLIENT_ID, + }, +) +``` + +#### 3. Setup CORS +Ensure you have CORS enabled for your local environment, such as `http://localhost:8000`. + +#### 4. Configure FastAPI-Azure-Auth +Configure either your [`SingleTenantAzureAuthorizationCodeBearer`](https://intility.github.io/fastapi-azure-auth/settings/single_tenant) +or [`MultiTenantAzureAuthorizationCodeBearer`](https://intility.github.io/fastapi-azure-auth/settings/multi_tenant). + + +```python +# file: demoproj/api/dependencies.py +from fastapi_azure_auth.auth import SingleTenantAzureAuthorizationCodeBearer + +azure_scheme = SingleTenantAzureAuthorizationCodeBearer( + app_client_id=settings.APP_CLIENT_ID, + tenant_id=settings.TENANT_ID, + scopes={ + f'api://{settings.APP_CLIENT_ID}/user_impersonation': 'user_impersonation', + } +) +``` +or for multi-tenant applications: +```python +# file: demoproj/api/dependencies.py +from fastapi_azure_auth.auth import MultiTenantAzureAuthorizationCodeBearer + +azure_scheme = MultiTenantAzureAuthorizationCodeBearer( + app_client_id=settings.APP_CLIENT_ID, + scopes={ + f'api://{settings.APP_CLIENT_ID}/user_impersonation': 'user_impersonation', + }, + validate_iss=False +) +``` +To validate the `iss`, configure an +[`iss_callable`](https://intility.github.io/fastapi-azure-auth/multi-tenant/accept_specific_tenants_only). + +#### 5. Configure dependencies + +Add `azure_scheme` as a dependency for your views/routers, using either `Security()` or `Depends()`. +```python +# file: main.py +from demoproj.api.dependencies import azure_scheme + +app.include_router(api_router, prefix=settings.API_V1_STR, dependencies=[Security(azure_scheme, scopes=['user_impersonation'])]) +``` + +#### 6. Load config on startup + +Optional but recommended. + +```python +# file: main.py +@app.on_event('startup') +async def load_config() -> None: + """ + Load OpenID config on startup. + """ + await azure_scheme.openid_config.load_config() +``` + + +## 📄 Example OpenAPI documentation +Your OpenAPI documentation will get an `Authorize` button, which can be used to authenticate. + + +The user can select which scopes to authenticate with, based on your configuration. + + + +%package -n python3-fastapi-azure-auth +Summary: Easy and secure implementation of Azure AD for your FastAPI APIs +Provides: python-fastapi-azure-auth +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-fastapi-azure-auth +<h1 align="center"> + <img margin="0 10px 0 0" src="https://avatars.githubusercontent.com/u/35199565" width="124px"/> + <img margin="0 10px 0 0" src="https://raw.githubusercontent.com/Intility/fastapi-azure-auth/main/docs/static/img/global/fastad.png" width="124px"/><br/> + FastAPI-Azure-Auth +</h1> + +<p align="center"> + <em>Azure AD Authentication for FastAPI apps made easy.</em> +</p> +<p align="center"> + <!-- Line 1 --> + <a href="https://python.org"> + <img src="https://img.shields.io/badge/python-v3.8+-blue.svg?logo=python&logoColor=white&label=python" alt="Python version"> + </a> + <a href="https://fastapi.tiangolo.com/"> + <img src="https://img.shields.io/badge/FastAPI-0.68.0+%20-blue.svg?logo=fastapi&logoColor=white&label=fastapi" alt="FastAPI Version"> + </a> + <a href="https://pypi.org/pypi/fastapi-azure-auth"> + <img src="https://img.shields.io/pypi/v/fastapi-azure-auth.svg?logo=pypi&logoColor=white&label=pypi" alt="Package version"> + </a> + <!-- Line 2 --> + <br/> + <a href="https://codecov.io/gh/intility/fastapi-azure-auth"> + <img src="https://codecov.io/gh/intility/fastapi-azure-auth/branch/main/graph/badge.svg?token=BTFGII4GYR" alt="Codecov"> + </a> + <a href="https://github.com/pre-commit/pre-commit"> + <img src="https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white" alt="Pre-commit"> + </a> + <a href="https://github.com/psf/black"> + <img src="https://img.shields.io/badge/code%20style-black-000000.svg" alt="Black"> + </a> + <a href="http://mypy-lang.org"> + <img src="http://www.mypy-lang.org/static/mypy_badge.svg" alt="mypy"> + </a> + <a href="https://pycqa.github.io/isort/"> + <img src="https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336" alt="isort"> + </a> + <!-- Line 3 --> + <br/> + <a href="https://docs.microsoft.com/en-us/azure/active-directory/develop/single-and-multi-tenant-apps"> + <img src="https://img.shields.io/badge/Single--tenant-Supported-blue?logo=Microsoft%20Azure&logoColor=white"> + </a> + <a href="https://docs.microsoft.com/en-us/azure/active-directory/develop/single-and-multi-tenant-apps"> + <img src="https://img.shields.io/badge/Multi--tenant-Supported-blue?logo=Microsoft%20Azure&logoColor=white"> + </a> +</p> + + +## 🚀 Description + +> FastAPI is a modern, fast (high-performance), web framework for building APIs with Python, based on standard Python type hints. + +At Intility we use FastAPI for both internal (single-tenant) and customer-facing (multi-tenant) APIs. This package enables our developers (and you 😊) to create features without worrying about authentication and authorization. + +Also, [we're hiring!](https://intility.no/en/career/) + +## 📚 Resources + +The [documentation](https://intility.github.io/fastapi-azure-auth/) contains a full tutorial on how to configure Azure AD +and FastAPI for both single- and multi-tenant applications. It includes examples on how to lock down +your APIs to certain scopes, tenants, roles etc. For first time users it's strongly advised to set up your +application exactly how it's described there, and then alter it to your needs later. + +[**MIT License**](https://github.com/Intility/fastapi-azure-auth/blob/main/LICENSE) +| [**Documentation**](https://intility.github.io/fastapi-azure-auth/) +| [**GitHub**](https://github.com/snok/django-guid) + + +## ⚡ Setup + +This is a tl;dr intended to give you an idea of what this package does and how to use it. +For a more in-depth tutorial and settings reference you should read the +[documentation](https://intility.github.io/fastapi-azure-auth/). + + +#### 1. Install this library: +```bash +pip install fastapi-azure-auth +# or +poetry add fastapi-azure-auth +``` + +#### 2. Configure your FastAPI app +Include `swagger_ui_oauth2_redirect_url` and `swagger_ui_init_oauth` in your FastAPI app initialization: + +```python +# file: main.py +app = FastAPI( + ... + swagger_ui_oauth2_redirect_url='/oauth2-redirect', + swagger_ui_init_oauth={ + 'usePkceWithAuthorizationCodeGrant': True, + 'clientId': settings.OPENAPI_CLIENT_ID, + }, +) +``` + +#### 3. Setup CORS +Ensure you have CORS enabled for your local environment, such as `http://localhost:8000`. + +#### 4. Configure FastAPI-Azure-Auth +Configure either your [`SingleTenantAzureAuthorizationCodeBearer`](https://intility.github.io/fastapi-azure-auth/settings/single_tenant) +or [`MultiTenantAzureAuthorizationCodeBearer`](https://intility.github.io/fastapi-azure-auth/settings/multi_tenant). + + +```python +# file: demoproj/api/dependencies.py +from fastapi_azure_auth.auth import SingleTenantAzureAuthorizationCodeBearer + +azure_scheme = SingleTenantAzureAuthorizationCodeBearer( + app_client_id=settings.APP_CLIENT_ID, + tenant_id=settings.TENANT_ID, + scopes={ + f'api://{settings.APP_CLIENT_ID}/user_impersonation': 'user_impersonation', + } +) +``` +or for multi-tenant applications: +```python +# file: demoproj/api/dependencies.py +from fastapi_azure_auth.auth import MultiTenantAzureAuthorizationCodeBearer + +azure_scheme = MultiTenantAzureAuthorizationCodeBearer( + app_client_id=settings.APP_CLIENT_ID, + scopes={ + f'api://{settings.APP_CLIENT_ID}/user_impersonation': 'user_impersonation', + }, + validate_iss=False +) +``` +To validate the `iss`, configure an +[`iss_callable`](https://intility.github.io/fastapi-azure-auth/multi-tenant/accept_specific_tenants_only). + +#### 5. Configure dependencies + +Add `azure_scheme` as a dependency for your views/routers, using either `Security()` or `Depends()`. +```python +# file: main.py +from demoproj.api.dependencies import azure_scheme + +app.include_router(api_router, prefix=settings.API_V1_STR, dependencies=[Security(azure_scheme, scopes=['user_impersonation'])]) +``` + +#### 6. Load config on startup + +Optional but recommended. + +```python +# file: main.py +@app.on_event('startup') +async def load_config() -> None: + """ + Load OpenID config on startup. + """ + await azure_scheme.openid_config.load_config() +``` + + +## 📄 Example OpenAPI documentation +Your OpenAPI documentation will get an `Authorize` button, which can be used to authenticate. + + +The user can select which scopes to authenticate with, based on your configuration. + + + +%package help +Summary: Development documents and examples for fastapi-azure-auth +Provides: python3-fastapi-azure-auth-doc +%description help +<h1 align="center"> + <img margin="0 10px 0 0" src="https://avatars.githubusercontent.com/u/35199565" width="124px"/> + <img margin="0 10px 0 0" src="https://raw.githubusercontent.com/Intility/fastapi-azure-auth/main/docs/static/img/global/fastad.png" width="124px"/><br/> + FastAPI-Azure-Auth +</h1> + +<p align="center"> + <em>Azure AD Authentication for FastAPI apps made easy.</em> +</p> +<p align="center"> + <!-- Line 1 --> + <a href="https://python.org"> + <img src="https://img.shields.io/badge/python-v3.8+-blue.svg?logo=python&logoColor=white&label=python" alt="Python version"> + </a> + <a href="https://fastapi.tiangolo.com/"> + <img src="https://img.shields.io/badge/FastAPI-0.68.0+%20-blue.svg?logo=fastapi&logoColor=white&label=fastapi" alt="FastAPI Version"> + </a> + <a href="https://pypi.org/pypi/fastapi-azure-auth"> + <img src="https://img.shields.io/pypi/v/fastapi-azure-auth.svg?logo=pypi&logoColor=white&label=pypi" alt="Package version"> + </a> + <!-- Line 2 --> + <br/> + <a href="https://codecov.io/gh/intility/fastapi-azure-auth"> + <img src="https://codecov.io/gh/intility/fastapi-azure-auth/branch/main/graph/badge.svg?token=BTFGII4GYR" alt="Codecov"> + </a> + <a href="https://github.com/pre-commit/pre-commit"> + <img src="https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white" alt="Pre-commit"> + </a> + <a href="https://github.com/psf/black"> + <img src="https://img.shields.io/badge/code%20style-black-000000.svg" alt="Black"> + </a> + <a href="http://mypy-lang.org"> + <img src="http://www.mypy-lang.org/static/mypy_badge.svg" alt="mypy"> + </a> + <a href="https://pycqa.github.io/isort/"> + <img src="https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336" alt="isort"> + </a> + <!-- Line 3 --> + <br/> + <a href="https://docs.microsoft.com/en-us/azure/active-directory/develop/single-and-multi-tenant-apps"> + <img src="https://img.shields.io/badge/Single--tenant-Supported-blue?logo=Microsoft%20Azure&logoColor=white"> + </a> + <a href="https://docs.microsoft.com/en-us/azure/active-directory/develop/single-and-multi-tenant-apps"> + <img src="https://img.shields.io/badge/Multi--tenant-Supported-blue?logo=Microsoft%20Azure&logoColor=white"> + </a> +</p> + + +## 🚀 Description + +> FastAPI is a modern, fast (high-performance), web framework for building APIs with Python, based on standard Python type hints. + +At Intility we use FastAPI for both internal (single-tenant) and customer-facing (multi-tenant) APIs. This package enables our developers (and you 😊) to create features without worrying about authentication and authorization. + +Also, [we're hiring!](https://intility.no/en/career/) + +## 📚 Resources + +The [documentation](https://intility.github.io/fastapi-azure-auth/) contains a full tutorial on how to configure Azure AD +and FastAPI for both single- and multi-tenant applications. It includes examples on how to lock down +your APIs to certain scopes, tenants, roles etc. For first time users it's strongly advised to set up your +application exactly how it's described there, and then alter it to your needs later. + +[**MIT License**](https://github.com/Intility/fastapi-azure-auth/blob/main/LICENSE) +| [**Documentation**](https://intility.github.io/fastapi-azure-auth/) +| [**GitHub**](https://github.com/snok/django-guid) + + +## ⚡ Setup + +This is a tl;dr intended to give you an idea of what this package does and how to use it. +For a more in-depth tutorial and settings reference you should read the +[documentation](https://intility.github.io/fastapi-azure-auth/). + + +#### 1. Install this library: +```bash +pip install fastapi-azure-auth +# or +poetry add fastapi-azure-auth +``` + +#### 2. Configure your FastAPI app +Include `swagger_ui_oauth2_redirect_url` and `swagger_ui_init_oauth` in your FastAPI app initialization: + +```python +# file: main.py +app = FastAPI( + ... + swagger_ui_oauth2_redirect_url='/oauth2-redirect', + swagger_ui_init_oauth={ + 'usePkceWithAuthorizationCodeGrant': True, + 'clientId': settings.OPENAPI_CLIENT_ID, + }, +) +``` + +#### 3. Setup CORS +Ensure you have CORS enabled for your local environment, such as `http://localhost:8000`. + +#### 4. Configure FastAPI-Azure-Auth +Configure either your [`SingleTenantAzureAuthorizationCodeBearer`](https://intility.github.io/fastapi-azure-auth/settings/single_tenant) +or [`MultiTenantAzureAuthorizationCodeBearer`](https://intility.github.io/fastapi-azure-auth/settings/multi_tenant). + + +```python +# file: demoproj/api/dependencies.py +from fastapi_azure_auth.auth import SingleTenantAzureAuthorizationCodeBearer + +azure_scheme = SingleTenantAzureAuthorizationCodeBearer( + app_client_id=settings.APP_CLIENT_ID, + tenant_id=settings.TENANT_ID, + scopes={ + f'api://{settings.APP_CLIENT_ID}/user_impersonation': 'user_impersonation', + } +) +``` +or for multi-tenant applications: +```python +# file: demoproj/api/dependencies.py +from fastapi_azure_auth.auth import MultiTenantAzureAuthorizationCodeBearer + +azure_scheme = MultiTenantAzureAuthorizationCodeBearer( + app_client_id=settings.APP_CLIENT_ID, + scopes={ + f'api://{settings.APP_CLIENT_ID}/user_impersonation': 'user_impersonation', + }, + validate_iss=False +) +``` +To validate the `iss`, configure an +[`iss_callable`](https://intility.github.io/fastapi-azure-auth/multi-tenant/accept_specific_tenants_only). + +#### 5. Configure dependencies + +Add `azure_scheme` as a dependency for your views/routers, using either `Security()` or `Depends()`. +```python +# file: main.py +from demoproj.api.dependencies import azure_scheme + +app.include_router(api_router, prefix=settings.API_V1_STR, dependencies=[Security(azure_scheme, scopes=['user_impersonation'])]) +``` + +#### 6. Load config on startup + +Optional but recommended. + +```python +# file: main.py +@app.on_event('startup') +async def load_config() -> None: + """ + Load OpenID config on startup. + """ + await azure_scheme.openid_config.load_config() +``` + + +## 📄 Example OpenAPI documentation +Your OpenAPI documentation will get an `Authorize` button, which can be used to authenticate. + + +The user can select which scopes to authenticate with, based on your configuration. + + + +%prep +%autosetup -n fastapi_azure_auth-4.1.1 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "\"/%h/%f\"\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "\"/%h/%f\"\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "\"/%h/%f\"\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "\"/%h/%f\"\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "\"/%h/%f.gz\"\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-fastapi-azure-auth -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Fri Jun 09 2023 Python_Bot <Python_Bot@openeuler.org> - 4.1.1-1 +- Package Spec generated @@ -0,0 +1 @@ +a85f88dd6dd632e2425a3f9e01731e37 fastapi_azure_auth-4.1.1.tar.gz |