

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

# OAuth 2.0/JWT authorizer contoh untuk AWS SAM
<a name="serverless-controlling-access-to-apis-oauth2-authorizer"></a>

[Anda dapat mengontrol akses ke APIs penggunaan Anda JWTs sebagai bagian dari [OpenID Connect (OIDC)](https://openid.net/specs/openid-connect-core-1_0.html) dan 2.0 framework. OAuth ](https://oauth.net/2/) Untuk melakukannya, Anda menggunakan tipe data [HttpApiAuth](sam-property-httpapi-httpapiauth.md).

Berikut ini adalah contoh bagian AWS SAM template untuk OAuth 2.0/JWT authorizer:

```
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 [Mengontrol akses ke HTTP APIs dengan otorisasi JWT di Panduan Pengembang API Gateway](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-jwt-authorizer.html).*