Token导航 LogoToken导航TokenDH.com
前端设计敏感数据github未标认证来源可访问许可证需确认审计通过

auth0-fastapi-apiauth0 FastAPI API 文档

Agent Skill

用于辅助 API 设计、接口文档、请求响应结构和服务集成说明。它适合让 Agent 梳理 endpoint、生成 OpenAPI 草稿、检查字段命名、整理错误码或辅助前后端联调。使用时需要确认真实业务语义、鉴权方式、分页和错误处理规则;涉及生成接口文档时,应避免凭空补字段,最好从现有代码、schema 或接口样例中提取事实。

总安装

1,576

周安装

65

GitHub Stars

17

下载量

515
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:auth0-fastapi-api(auth0 FastAPI API 文档)
来源仓库:https://github.com/auth0/agent-skills
仓库路径:skills/auth0-fastapi-api
安装命令:
npx skills add https://github.com/auth0/agent-skills --skill auth0-fastapi-api
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/auth0/agent-skills --skill auth0-fastapi-api

简介

用于辅助 API 设计、接口文档、请求响应结构和服务集成说明。

  • 适合梳理 endpoint、生成 OpenAPI 草稿、检查字段命名或整理错误码。
  • 通过系统步骤发现项目结构、识别认证文件和中间件配置,提供路由保护建议。
  • 使用时需要确认真实业务语义、鉴权方式、分页和错误处理规则。
  • auth0-fastapi-api 属于前端设计类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Auth0 FastAPI API Integration

Protect FastAPI API endpoints with JWT access token validation using auth0-fastapi-api.

Note: This SDK is currently in beta. The API surface may change before the stable 1.0 release. Check PyPI for the latest version. Requires Python >= 3.9 and FastAPI >= 0.115.11.

Prerequisites

  • FastAPI application (Python 3.9+)
  • Auth0 API resource configured (not an Application — must be an API)
  • If you don't have Auth0 set up yet, use the auth0-quickstart skill first

When NOT to Use

  • Server-rendered web applications — Use a session-based login/logout flow instead
  • Single Page Applications — Use auth0-react, auth0-vue, or auth0-angular for client-side auth
  • Mobile applications — Use auth0-react-native or auth0-android
  • Issuing tokens — This skill is for *validating* access tokens, not issuing them

Quick Start Workflow

1. Install SDK

pip install auth0-fastapi-api python-dotenv

2. Create Auth0 API

You need an API (not Application) in Auth0.

STOP — ask the user before proceeding. Ask exactly this question and wait for their answer before doing anything else: > "How would you like to create the Auth0 API resource? > > 1. Automated — I'll run Auth0 CLI scripts that create the resource and write the exact values to your .env automatically. > 2. Manual — You create the API yourself in the Auth0 Dashboard (or via auth0 apis create) and provide me the Domain and Audience. > > Which do you prefer? (1 = Automated / 2 = Manual)" Do NOT proceed to any setup steps until the user has answered. Do NOT default to manual.

If the user chose Automated, follow the Setup Guide for complete CLI scripts. The automated path writes .env for you — skip Step 3 below and proceed directly to Step 4.

If the user chose Manual, follow the Setup Guide (Manual Setup section) for full instructions. Then continue with Step 3 below.

Quick reference for manual API creation:

# Using Auth0 CLI
auth0 apis create \
  --name "My FastAPI API" \
  --identifier https://my-api.example.com

Or create manually in Auth0 Dashboard → Applications → APIs

3. Configure Environment

Create .env:

AUTH0_DOMAIN=your-tenant.us.auth0.com
AUTH0_AUDIENCE=https://your-api.example.com

AUTH0_DOMAIN is your Auth0 tenant domain (without https://). AUTH0_AUDIENCE is the API identifier you set when creating the API resource in Auth0.

4. Initialize Auth0

import os
from fastapi import FastAPI, Depends
from fastapi_plugin import Auth0FastAPI
from dotenv import load_dotenv

load_dotenv()

app = FastAPI()

auth0 = Auth0FastAPI(
    domain=os.getenv("AUTH0_DOMAIN"),
    audience=os.getenv("AUTH0_AUDIENCE"),
)

Create one Auth0FastAPI instance per application and reuse it across routes. Never hardcode the domain or audience — always use environment variables.

5. Protect Routes

# Require any valid access token
@app.get("/api/private")
async def private(claims: dict = Depends(auth0.require_auth())):
    return {"user": claims["sub"]}

# No authentication required
@app.get("/api/public")
async def public():
    return {"message": "Public endpoint"}

The require_auth() dependency validates the Bearer token, verifies the issuer and audience, and returns the decoded JWT claims.

Error responses:

  • 400 invalid_request — Missing or malformed Authorization header
  • 401 invalid_token — Expired token, invalid signature, wrong issuer/audience
  • 403 insufficient_scope — Valid token but missing required scopes
  • 500 internal_server_error — Unexpected errors

Response body format: {"detail": {"error": "...", "error_description": "..."}}

6. Protect Routes with Scope Checks

# Requires the read:messages scope
@app.get("/api/messages")
async def get_messages(claims: dict = Depends(auth0.require_auth(scopes="read:messages"))):
    return {"messages": []}

# Requires both read:data and write:data scopes
@app.post("/api/data")
async def write_data(claims: dict = Depends(auth0.require_auth(scopes=["read:data", "write:data"]))):
    return {"created": True}

require_auth(scopes=...) checks the scope claim in the JWT. All specified scopes must be present (AND logic). Missing scopes return 403.

7. Access Token Claims

The decoded JWT claims are returned directly from the dependency:

@app.get("/api/profile")
async def profile(claims: dict = Depends(auth0.require_auth())):
    return {
        "sub": claims["sub"],       # user ID
        "scope": claims.get("scope"),  # granted scopes
    }

Key claims:

  • claims["sub"] — user/client ID
  • claims["scope"] — space-separated granted scopes
  • claims["iss"] — issuer (your Auth0 domain URL)
  • claims["aud"] — audience
  • claims["exp"] — expiration timestamp
  • claims["iat"] — issued-at timestamp

8. Protect Routes Without Needing Claims

@app.get("/api/protected", dependencies=[Depends(auth0.require_auth())])
async def protected():
    return {"message": "You need a valid access token to see this."}

9. Test the API

# No token — expect 401
curl http://localhost:8000/api/private

# With a valid access token
curl http://localhost:8000/api/private \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN"

Get a test token via Client Credentials flow or Auth0 Dashboard → APIs → Test tab.


Common Mistakes

MistakeFix
Hardcoding domain or audience in sourceAlways read from environment variables — never embed credentials in code
Using python-jose or PyJWT directlyNot needed; auth0-fastapi-api handles all validation via JWKS
Manually parsing Authorization headerThe SDK extracts and validates the token automatically
Calling jwt.decode() manuallyThe SDK verifies tokens against the JWKS endpoint — do not verify yourself
Using fastapi-users for Auth0 JWT validationThat package is for user management, not Auth0 JWT verification
Created an Application instead of an API in Auth0Must create an API resource (Applications → APIs) — an Application doesn't issue access tokens with the right audience
Passing domain as full URL with https://domain should be the bare domain, e.g. my-tenant.us.auth0.com, not https://my-tenant.us.auth0.com
Using an ID token instead of an access tokenMust use the access token for API auth — ID tokens are for the client app, not for API authorization
Not configuring CORS for SPA clientsAdd CORSMiddleware to allow requests from your frontend origin
os.getenv() returns None silentlyEnsure python-dotenv is installed and load_dotenv() is called before Auth0FastAPI() initialization — or use os.environ[] to fail fast

DPoP Support

Built-in proof-of-possession token binding per RFC 9449. DPoP is enabled by default in mixed mode (accepts both Bearer and DPoP tokens). See Integration Guide for configuration.


Related Skills

  • auth0-quickstart - Basic Auth0 setup and framework detection
  • auth0-mfa - Add Multi-Factor Authentication

Quick Reference

Auth0FastAPI configuration:

auth0 = Auth0FastAPI(
    domain=os.getenv("AUTH0_DOMAIN"),       # required (or use domains)
    audience=os.getenv("AUTH0_AUDIENCE"),    # required
    dpop_enabled=True,                       # default; set False for Bearer-only
    dpop_required=False,                     # default; set True to reject Bearer tokens
)

Route protection:

Depends(auth0.require_auth())                    # any valid token
Depends(auth0.require_auth(scopes="read:res"))   # single scope
Depends(auth0.require_auth(scopes=["r", "w"]))   # all scopes required

Accessing claims:

claims["sub"]           # user/client ID
claims["scope"]         # space-separated scopes

Environment variables:

  • AUTH0_DOMAIN — your Auth0 tenant domain (e.g. tenant.us.auth0.com)
  • AUTH0_AUDIENCE — your API identifier (e.g. https://api.example.com)

Common Use Cases:

  • Protect routes → Depends(auth0.require_auth()) (see Step 5)
  • Scope enforcement → Depends(auth0.require_auth(scopes="...")) (see Step 6)
  • DPoP token binding → Integration Guide
  • Reverse proxy setup → Integration Guide
  • Advanced configuration → API Reference

Detailed Documentation

  • Setup Guide — Auth0 CLI setup, environment configuration, getting test tokens
  • Integration Guide — DPoP, scopes, error handling, reverse proxy, testing
  • API Reference — Complete constructor options, method signatures, error codes

References

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

37.03%
按下载量换算191

Claude

28.21%
按下载量换算145

Cursor

18.27%
按下载量换算94

Gemini CLI

8.88%
按下载量换算46

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills