

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# の OAuth 2.0/JWT オーソライザーの例 AWS SAM
<a name="serverless-controlling-access-to-apis-oauth2-authorizer"></a>

API へのアクセスは、[OpenID Connect (OIDC)](https://openid.net/specs/openid-connect-core-1_0.html) および [OAuth 2.0](https://oauth.net/2/) フレームワークの一部として JWT を使用することによって制御できます。これを実行するには、[HttpApiAuth](sam-property-httpapi-httpapiauth.md) データ型を使用します。

OAuth 2.0/JWT オーソライザーの AWS SAM テンプレートセクションの例を次に示します。

```
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 Gateway デベロッパーガイド*の「[JWT オーソライザーを使用した HTTP API へのアクセスの制御](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-jwt-authorizer.html)」を参照してください。