dpop-adoption
它能做什么
这项技能帮助开发人员保护 OAuth 刷新令牌,使被盗的令牌无法被他人使用。适合希望在 Google 登录中增强令牌安全性的团队。
适用场景
- ✓你想用 DPoP 把 Google OAuth 刷新令牌绑定到一个密钥的时候。
- ✓你需要为发送到 Google 令牌端点的请求创建证明 JWT 的时候。
- ✓令牌请求返回 use_dpop_nonce 挑战、需要重试的时候。
技能链接
https://github.com/google/skills/blob/main/skills/identity/dpop-adoption/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请为我的浏览器应用的 Google 登录添加 DPoP,让刷新令牌绑定到一个无法导出的密钥上。”
每周 5 个新技能,1 分钟读完。
工作原理
它会说明如何生成无法提取的 P-256 密钥对,为每个令牌请求签署 DPoP 证明,并在 Google 要求 nonce 时重试。它使用标准的 Web Crypto API。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
DPoP Adoption & Identity Security Architecture
Demonstrating Proof-of-Possession (DPoP, RFC 9449) secures OAuth 2.0 refresh
tokens against interception and replay attacks by cryptographically binding them
to a private key held exclusively by the client. In Google's OAuth 2.0 platform,
DPoP binds the refresh token at the token endpoint, while access tokens issued
for Google APIs are standard Bearer tokens (token_type: "Bearer").
1. Core Cryptographic & Architectural Invariants
When implementing DPoP helpers or upgrading HTTP clients, you MUST adhere to the following strict security invariants:
A. Universal WebCrypto & Runtime Compatibility
- In modern ES6 JavaScript (
"type": "module"for Node 18+ and browsers), ALWAYS accessglobalThis.cryptodirectly after verifying the environment context. - NEVER import legacy CommonJS modules via
require('node:crypto')or reference browser-scopedwindow.crypto, as these cause module initialization crashes across hybrid runtimes.
B. Hardware-Backed Non-Extractable Key Persistence
- Generate an Elliptic Curve key pair on the SECP256R1 (
P-256) curve:{ name: 'ECDSA', namedCurve: 'P-256' }. - CRITICAL SECURITY GUARDRAIL: The private key MUST be configured as
non-extractable (
extractable: false). This guarantees the private key can never leave the hardware cryptographic boundary (Secure Enclave, Android KeyStore, or JS sandbox memory), thwarting XSS and dependency token theft attacks. - The public key MUST remain exportable (
extractable: true) to allow emitting JSON Web Keys (JWKs).
C. Public JWK Formatting Standards
- When exporting public keys to attach to DPoP Proof JWT headers, construct a
clean JWK dictionary containing strictly:
"kty": "EC""crv": "P-256""x": Base64URL-encoded x-coordinate without trailing equal sign padding (=)."y": Base64URL-encoded y-coordinate without trailing equal sign padding (=).
- NEVER expose private key parameters (
"d") or superfluous metadata.
D. IEEE P1363 vs. ASN.1 DER Signature Disambiguation
- DPoP Proof JWTs require raw concatenated coordinate signatures ($R \parallel S$, exactly 64 bytes for P-256) per IEEE P1363 and RFC 7518.
- WebCrypto Native Rule: In standard WebCrypto (
crypto.subtle.sign), ECDSA signatures are ALREADY emitted natively in raw IEEE P1363 format (concatenated 32-byterandsbuffers, 64 bytes total). DO NOT attempt DER-to-Raw conversion oncrypto.subtle.signoutputs, as parsing a 64-byte raw buffer as ASN.1 DER causes an immediate runtime exception (Invalid DER sequence). Directly base64url-encode the raw ArrayBuffer. - Legacy API Fallback: If and only if implementing in legacy Java/Android
(
java.security.Signature) or Node CommonJS (crypto.createSign), convert ASN.1 DER output to raw 64-byte IEEE P1363 format before base64url encoding.
E. SPA & Backend-for-Frontend (BFF) Architecture
- Secretless SPAs Limitation: Pure client-side single-page applications
(SPAs) without a backend cannot use DPoP directly with Google APIs due to
client_secretrequirements on server endpoints and browser CORS limitations on theDPoP-Nonceresponse header. - BFF Pattern: To secure SPAs with DPoP, route authorization and token
refresh requests through a Backend-for-Frontend (BFF) server-side client.
The BFF sets
access_type=offline, binds refresh tokens server-side using DPoP, and maintains secure session cookies with the frontend.
2. Implementation Rules & Mandatory Public API
When creating new modules, your module MUST explicitly export all functions below to integrate cleanly with CI/CD verification harnesses and automated probers. When inspecting or refactoring existing codebases, ensure equivalent cryptographic and RFC 9449 logic is present. Obey strict claim derivation logic in all cases:
A. DPoP Proof JWT Claim Derivation Rules (createDPoPProof)
When generating the DPoP Proof JWT in createDPoPProof:
1. JOSE Header (typ, alg, jwk):
// Header
{
"typ": "dpop+jwt",
"alg": "ES256",
"jwk": await exportPublicJWK(publicKey)
}
2. Payload Claims:
"htm": Uppercase HTTP Method ("POST"for token requests)."htu": Target URI stripped of query parameters and hash fragments using `sanitizeH
常见问题
私钥能被复制出来吗?
不能。密钥被设置为不可提取,因此无法离开加密系统。
Google API 访问令牌会改变吗?
不会。访问令牌仍是标准的 Bearer 令牌,DPoP 只绑定刷新令牌。
它覆盖哪些运行环境?
浏览器、WebCrypto 和 Node.js ES 模块的设置。
详情
作者的原始描述
Implement and debug OAuth 2.0 DPoP (RFC 9449) refresh token sender-constraining for WebCrypto, Node.js ES6, and browser runtimes integrating with Google's OAuth platform. Use when configuring non-extractable asymmetric key pairs (P-256), generating DPoP Proof JWTs for authorization code exchange and token refresh, or handling 400 use_dpop_nonce challenge retry loops at oauth2.googleapis.com/token. Don't use for unconstrained OAuth 2.0 flows (where refresh tokens are not bound to a client key pair), or for Google Cloud IAM / service account authentication.
repo: google/skills
热度
- GitHub 星标
- 22k
- 排名
- #10354
- 许可证
- Apache-2.0
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
finding-google-skills
22k帮你的智能体为某项设置任务找到合适的 Google 指南,例如托管、数据库、存储、登录或 AI 模型服务。
gcloud
22k帮你的智能体编写并检查 Google Cloud gcloud 命令,在运行任何内容之前查阅准确的语法,避免猜测参数。
google-cloud-recipe-auth
22k引导你的智能体了解 Google Cloud 的身份与访问管理,包括人员和服务如何登录,以及它们各自获得哪些权限。
google-cloud-recipe-onboarding
22k带领新开发者完成在 Google Cloud 上的第一步,包括选择项目、关联计费,以及部署第一个资源。