ybelenko / oauth2_as_oas3_components
OAuth2 定义作为 OpenAPI Spec 3.0 组件
This package is auto-updated.
Last update: 2024-09-21 04:38:51 UTC
README
示例文件描述了 OAuth2 令牌端点,位于 dist/oauth2_endpoints.yml。
此包存在的理由
由于 RFC 6749 OAuth2 服务器实现可能非常不同(可选/推荐响应字段,扩展授权),在您的 OAS3 文件中描述您的独特实现可能很有用。查看您的令牌和错误响应的示例也非常方便,因为 RFC6749 是一个没有图片或图表的文本文档。前面提到的示例文件包含了每个授权授权的令牌端点描述,将其视为起点。
故意省略示例文件中的 授权端点 端点。由于端点响应不是 JSON(html 页面),我不知道如何使用 OAS3 来描述它。如果您有任何建议,请向此存储库提交问题。
由于 RFC 6749 - OAuth2.0 授权框架 - 2.3.1. 客户端密码 不建议在请求正文中发送客户端密码,因此我们的示例期望所有端点都使用基本身份验证。
安装
复制粘贴
由于它实际上不是代码,而是标记,您可以从 dist/oauth2_endpoints.yml 中复制任何您想要的内容。
在 dist/oauth2_endpoints_polymorphism.yml 中还有增强的示例,包含多态性。请确保您的工具支持多态性。此示例包含尚未广泛采用的新功能。至少检查 oneOf 属性的支持。我不会使用它,因为大多数 OpenAPI 工具现在都存在多态性问题,但此示例可能在可预见的未来很有用。
Composer
然后在终端中运行
composer require ybelenko/oauth2_as_oas3_components
使用 $ref 属性通过提供的组件,如
paths: /token: post: summary: Obtain access token with "authorization_code" grant. requestBody: $ref: './vendor/ybelenko/oauth2_as_oas3_components/dist/components/requestBodies/TokenRequestCodeGrant.yml' responses: '200': $ref: './vendor/ybelenko/oauth2_as_oas3_components/dist/components/responses/OAuth2TokenSuccessResponse.yml' '4XX': $ref: './vendor/ybelenko/oauth2_as_oas3_components/dist/components/responses/OAuth2TokenErrorResponse.yml'
包含引用的扩展示例 dist/oauth2_endpoints_with_refs.yml
NPM
然后在终端中运行
npm i --save oauth2_as_oas3_components
使用 $ref 属性通过提供的组件,如
paths: /token: post: summary: Obtain access token with "authorization_code" grant. requestBody: $ref: './node_modules/oauth2_as_oas3_components/dist/components/requestBodies/TokenRequestCodeGrant.yml' responses: '200': $ref: './node_modules/oauth2_as_oas3_components/dist/components/responses/OAuth2TokenSuccessResponse.yml' '4XX': $ref: './node_modules/oauth2_as_oas3_components/dist/components/responses/OAuth2TokenErrorResponse.yml'
包含引用的扩展示例 dist/oauth2_endpoints_with_refs.yml
贡献
如果您有任何建议,请提交问题。