phantom_token_client_credential
`phantom_token_client_credential` 指令在 Phantom Token NGINX Module 中为 OAuth token introspection 配置 base64 编码的客户端凭证。
说明
phantom_token_client_credential 指令对于 Phantom Token NGINX Module 至关重要,该模块通过向 Curity Identity Server 发送客户端凭证来实现 OAuth 2.0 Token Introspection 标准。该指令需要两个参数:一个 base64 编码的 client ID 和 client secret 配对。当请求在 Authorization header 中携带 bearer token 时,NGINX 会提取该令牌,并使用本指令设置的客户端凭证调用指定的 introspection endpoint。如果 introspection 确认令牌有效,则会提取相应的 JWT 并转发给后端服务;如果令牌无效或缺失,模块将通过返回 401 Unauthorized 响应来拒绝访问。
该指令的参数应以 base64 编码的形式提供,确保 client ID 和 client secret 在 introspection 过程中被安全传输。正确使用该指令至关重要,因为凭证中的任何错误都可能导致对后端 APIs 的身份验证和授权请求失败。该模块的整体运行确保只有携带有效令牌的请求才能访问受保护的资源,从而遵循微服务架构的安全最佳实践。
配置示例
location /api {
phantom_token_client_credential base64_encoded_client_id:base64_encoded_client_secret;
phantom_token_introspection_endpoint http://introspection.endpoint.com;
}确保 base64 客户端凭证被正确编码;编码不正确会导致身份验证失败。
注意敏感信息泄露;不要在可公开访问的配置中硬编码凭证。
确保 introspection endpoint 已正确配置且可访问,否则请求可能会因无法 introspect the token 而被拒绝。