Contoh otorisasi OAuth 2.0/JWT - AWS Serverless Application Model

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

Contoh otorisasi OAuth 2.0/JWT

Anda dapat mengendalikan akses ke API menggunakan JWTs sebagai bagian dari kerangka kerja Connect OpenID (OIDC) dan OAuth 2.0. Untuk melakukannya, Anda menggunakan tipe data HttpApiAuth.

Berikut ini adalah bagian contoh AWS SAM template untuk otorisasi OAuth 2.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

Untuk informasi selengkapnya tentang otorisasi OAuth 2.0/JWT, lihat Mengendalikan akses ke API HTTP dengan otorisasi JWT di Panduan Developer API Gateway.