Posts

Showing posts with the label fastapi

Simple FastAPI App with Docker and Minikube

 Let's start with the simplest one. Which we can develop and test in our local system or laptop, or Mac. ✅ Simple FastAPI App with Docker and Minikube (Kubernetes) 📁 Folder Structure fastapi-k8s-demo/ ├── app/ │ └── main.py ├── Dockerfile ├── requirements.txt ├── k8s/ │ ├── deployment.yaml │ └── service.yaml 📄 app/main.py from fastapi import FastAPI app = FastAPI() @app.get("/") def read_root(): return {"message": "Hello from FastAPI on Kubernetes!"} 📄 requirements.txt fastapi uvicorn 📄 Dockerfile FROM python:3.11-slim WORKDIR /app COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY app/ . CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] 📄 k8s/deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: fastapi-deployment spec: replicas: 1 selector: matchLabels: app: fastapi template: metadata: ...

Integrating Authentication OAuth 2.0

Integrating authentication protocols like Azure AD (which heavily uses OAuth 2.0) and generic OAuth 2.0 into your APIs is crucial for securing your applications. Here's a breakdown of how to approach this, including key concepts and best practices: Understanding OAuth 2.0 (the foundation) OAuth 2.0 is an authorization framework that enables an application to obtain limited access to a user's protected resources on an HTTP service (like your API), without revealing the user's credentials to the application. Instead, the application obtains an access token from an authorization server (e.g., Azure AD) after the user grants consent. Key Roles in OAuth 2.0: Resource Owner: The user who owns the data (e.g., their profile information, documents) that the client application wants to access. Client: The application (your API consumer, like a web app, mobile app, or another service) that wants to access the protected resources. Authorization Server: The server that issues acces...