View a markdown version of this page

OAuth 2. 0/JWT 的授权者示例 Amazon SAM - Amazon Serverless Application Model
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)。

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

OAuth 2. 0/JWT 的授权者示例 Amazon SAM

您可以使用 JWT 作为 OpenID Connect (OIDC) 和 OAuth 2.0 框架的一部分来控制对 API 的访问。为此,您需要使用 HttpApiAuth 数据类型。

以下是 OAuth 2 的示例 Amazon SAM 模板部分。 0/JWT授权者:

Resources: MyApi: Type: AWS::Serverless::HttpApi Properties: Auth: Authorizers: MyOauth2Authorizer: AuthorizationScopes: - scope IdentitySource: $request.header.Authorization JwtConfiguration: audience: - audience1 - audience2 issuer: "https://www.example.com/v1/connect/oidc" DefaultAuthorizer: MyOauth2Authorizer StageName: Prod MyFunction: Type: AWS::Serverless::Function Properties: CodeUri: ./src Events: GetRoot: Properties: ApiId: MyApi Method: get Path: / PayloadFormatVersion: "2.0" Type: HttpApi Handler: index.handler Runtime: nodejs12.x

有关 OAuth 2 的更多信息 0/JWT 授权方,请参阅《API Gate way 开发者指南》中的 “使用 JWT 授权者控制 HTTP API 的访问权限”。