쿠키 기본 설정 선택

당사는 사이트와 서비스를 제공하는 데 필요한 필수 쿠키 및 유사한 도구를 사용합니다. 고객이 사이트를 어떻게 사용하는지 파악하고 개선할 수 있도록 성능 쿠키를 사용해 익명의 통계를 수집합니다. 필수 쿠키는 비활성화할 수 없지만 '사용자 지정' 또는 ‘거부’를 클릭하여 성능 쿠키를 거부할 수 있습니다.

사용자가 동의하는 경우 AWS와 승인된 제3자도 쿠키를 사용하여 유용한 사이트 기능을 제공하고, 사용자의 기본 설정을 기억하고, 관련 광고를 비롯한 관련 콘텐츠를 표시합니다. 필수가 아닌 모든 쿠키를 수락하거나 거부하려면 ‘수락’ 또는 ‘거부’를 클릭하세요. 더 자세한 내용을 선택하려면 ‘사용자 정의’를 클릭하세요.

API Gateway에서 JWT 권한 부여자를 사용하여 HTTP API에 대한 액세스 제어

포커스 모드
API Gateway에서 JWT 권한 부여자를 사용하여 HTTP API에 대한 액세스 제어 - Amazon API Gateway

JWT(JSON Web Token)를 OIDC(OpenID Connect)OAuth 2.0 프레임워크의 일부로 사용하여 API에 대한 클라이언트 액세스를 제한할 수 있습니다.

API의 경로에 대해 JWT 권한 부여자를 구성하면 API Gateway는 클라이언트가 API 요청과 함께 제출하는 JWT를 검증합니다. API Gateway는 토큰 검증 및 선택적으로 토큰의 범위를 기반으로 요청을 허용하거나 거부합니다. 경로의 범위를 구성하는 경우 토큰에 경로의 범위 중 하나 이상이 포함되어야 합니다.

API의 각 경로에 대해 고유한 권한 부여자를 구성하거나, 여러 경로에 대해 동일한 권한 부여자를 사용할 수 있습니다.

참고

OpenID Connect ID 토큰과 같은 기타 유형의 JWT와 JWT 액세스 토큰을 구별하는 표준 메커니즘은 없습니다. API 인증에 ID 토큰이 필요하지 않은 경우 인증 범위가 필요하도록 경로를 구성하는 것이 좋습니다. 자격 증명 공급자가 JWT 액세스 토큰을 발급할 때만 사용하는 발급자 또는 대상 그룹이 필요하도록 JWT 권한 부여자를 구성할 수도 있습니다.

JWT 권한 부여자를 통한 API 요청 승인

API Gateway는 다음과 같은 일반 워크플로우를 사용하여 JWT 권한 부여자를 사용하도록 구성된 라우팅에 대한 요청을 승인합니다.

  1. 토큰에 대한 identitySource를 확인합니다. identitySource에는 토큰만 포함하거나 Bearer 접두사가 붙은 토큰만 포함될 수 있습니다.

  2. 토큰을 디코딩합니다.

  3. 발행자의 jwks_uri에서 가져온 퍼블릭 키를 사용하여 토큰의 알고리즘과 서명을 확인합니다. 현재 RSA 기반 알고리즘만 지원됩니다. API Gateway는 퍼블릭 키를 2시간 동안 캐시할 수 있습니다. 가장 좋은 방법은 키를 교체할 때 이전 키와 새 키가 모두 유효한 유예 기간을 두는 것입니다.

  4. 클레임을 검증합니다. API Gateway는 다음 토큰 클레임을 평가합니다.

    • kid – 토큰에는 토큰에 서명한 jwks_uri의 키와 일치하는 헤더 클레임이 있어야 합니다.

    • iss – 권한 부여자에 대해 구성된 issuer와 일치해야 합니다.

    • aud 또는 client_id – 권한 부여자에 대해 구성된 audience 항목 중 하나와 일치해야 합니다. API 게이트웨이는 aud가 없는 경우에만 client_id의 유효성을 검사합니다. audclient_id가 모두 있는 경우 API Gateway는 aud를 평가합니다.

    • exp – 현재 시간(UTC 기준) 이후여야 합니다.

    • nbf – 현재 시간(UTC 기준) 이전이어야 합니다.

    • iat – 현재 시간(UTC 기준) 이전이어야 합니다.

    • scope 또는 scp – 토큰에 라우팅의 authorizationScopes 범위 중 하나 이상이 포함되어야 합니다.

이러한 단계 중 하나가 실패하면 API Gateway는 API 요청을 거부합니다.

JWT를 검증한 후 API Gateway는 토큰의 클레임을 API 경로의 통합에 전달합니다. Lambda 함수와 같은 백엔드 리소스는 JWT 클레임에 액세스할 수 있습니다. 예를 들어, JWT에 자격 증명 클레임 emailID가 포함된 경우 $event.requestContext.authorizer.jwt.claims.emailID의 Lambda 통합에 해당 클레임을 사용할 수 있습니다. API Gateway가 Lambda 통합으로 보내는 페이로드에 대한 자세한 내용은 API Gateway에서 HTTP API에 대한 AWS Lambda 프록시 통합 생성 단원을 참조하세요.

JWT 권한 부여자 생성

JWT 권한 부여자를 생성하기 전에 클라이언트 애플리케이션을 자격 증명 공급자에 등록해야 합니다. 또한 HTTP API를 생성해야 합니다. HTTP API 생성 예제는 HTTP API 생성 단원을 참조하세요.

콘솔을 사용하여 JWT 권한 부여자를 생성하려는 경우

다음 단계는 콘솔을 사용하여 JWT 권한 부여자를 생성하는 방법을 보여줍니다.

콘솔을 사용하여 JWT 권한 부여자를 생성하려는 경우
  1. https://console.aws.amazon.com/apigateway에서 API Gateway 콘솔에 로그인합니다.

  2. HTTP API를 선택합니다.

  3. 기본 탐색 창에서 권한 부여자를 선택합니다.

  4. 권한 부여자 관리 탭을 선택합니다.

  5. 생성(Create)을 선택합니다.

  6. 권한 부여자 유형으로는 JWT를 선택합니다.

  7. JWT 권한 부여자를 구성하고 토큰 소스를 정의하는 ID 소스를 지정합니다.

  8. 생성(Create)을 선택합니다.

AWS CLI를 사용하여 사용자 지정 권한 부여자 생성

다음 create-authorizer 명령은 JWT 권한 부여자를 생성합니다. jwt-configuration의 경우 ID 공급자에 대한 AudienceIssuer를 지정합니다. Amazon Cognito를 ID 공급자로 사용하는 경우 IssuerUrlhttps://cognito-idp.us-east-2.amazonaws.com/userPoolID입니다.

aws apigatewayv2 create-authorizer \ --name authorizer-name \ --api-id api-id \ --authorizer-type JWT \ --identity-source '$request.header.Authorization' \ --jwt-configuration Audience=audience,Issuer=IssuerUrl
AWS CloudFormation을 사용하여 JWT 권한 부여자 생성

다음 AWS CloudFormation 템플릿은 Amazon Cognito를 ID 공급자로 사용하는 JWT 권한 부여자를 사용하여 HTTP API를 만듭니다.

AWS CloudFormation 템플릿의 출력은 Amazon Cognito 호스팅 UI의 URL로, 클라이언트가 가입하고 로그인하여 JWT를 받을 수 있습니다. 클라이언트가 로그인하면 URL에 액세스 토큰이 있는 HTTP API로 클라이언트가 리디렉션됩니다. 액세스 토큰으로 API를 간접 호출하려면 토큰을 쿼리 문자열 파라미터로 사용하도록 URL의 #?로 변경하세요.

AWSTemplateFormatVersion: '2010-09-09' Description: | Example HTTP API with a JWT authorizer. This template includes an Amazon Cognito user pool as the issuer for the JWT authorizer and an Amazon Cognito app client as the audience for the authorizer. The outputs include a URL for an Amazon Cognito hosted UI where clients can sign up and sign in to receive a JWT. After a client signs in, the client is redirected to your HTTP API with an access token in the URL. To invoke the API with the access token, change the '#' in the URL to a '?' to use the token as a query string parameter. Resources: MyAPI: Type: AWS::ApiGatewayV2::Api Properties: Description: Example HTTP API Name: api-with-auth ProtocolType: HTTP Target: !GetAtt MyLambdaFunction.Arn DefaultRouteOverrides: Type: AWS::ApiGatewayV2::ApiGatewayManagedOverrides Properties: ApiId: !Ref MyAPI Route: AuthorizationType: JWT AuthorizerId: !Ref JWTAuthorizer JWTAuthorizer: Type: AWS::ApiGatewayV2::Authorizer Properties: ApiId: !Ref MyAPI AuthorizerType: JWT IdentitySource: - '$request.querystring.access_token' JwtConfiguration: Audience: - !Ref AppClient Issuer: !Sub https://cognito-idp.${AWS::Region}.amazonaws.com/${UserPool} Name: test-jwt-authorizer MyLambdaFunction: Type: AWS::Lambda::Function Properties: Runtime: nodejs18.x Role: !GetAtt FunctionExecutionRole.Arn Handler: index.handler Code: ZipFile: | exports.handler = async (event) => { const response = { statusCode: 200, body: JSON.stringify('Hello from the ' + event.routeKey + ' route!'), }; return response; }; APIInvokeLambdaPermission: Type: AWS::Lambda::Permission Properties: FunctionName: !Ref MyLambdaFunction Action: lambda:InvokeFunction Principal: apigateway.amazonaws.com SourceArn: !Sub arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${MyAPI}/$default/$default FunctionExecutionRole: Type: AWS::IAM::Role Properties: AssumeRolePolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Principal: Service: - lambda.amazonaws.com Action: - 'sts:AssumeRole' ManagedPolicyArns: - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole UserPool: Type: AWS::Cognito::UserPool Properties: UserPoolName: http-api-user-pool AutoVerifiedAttributes: - email Schema: - Name: name AttributeDataType: String Mutable: true Required: true - Name: email AttributeDataType: String Mutable: false Required: true AppClient: Type: AWS::Cognito::UserPoolClient Properties: AllowedOAuthFlows: - implicit AllowedOAuthScopes: - aws.cognito.signin.user.admin - email - openid - profile AllowedOAuthFlowsUserPoolClient: true ClientName: api-app-client CallbackURLs: - !Sub https://${MyAPI}.execute-api.${AWS::Region}.amazonaws.com ExplicitAuthFlows: - ALLOW_USER_PASSWORD_AUTH - ALLOW_REFRESH_TOKEN_AUTH UserPoolId: !Ref UserPool SupportedIdentityProviders: - COGNITO HostedUI: Type: AWS::Cognito::UserPoolDomain Properties: Domain: !Join - '-' - - !Ref MyAPI - !Ref AppClient UserPoolId: !Ref UserPool Outputs: SignupURL: Value: !Sub https://${HostedUI}.auth.${AWS::Region}.amazoncognito.com/login?client_id=${AppClient}&response_type=token&scope=email+profile&redirect_uri=https://${MyAPI}.execute-api.${AWS::Region}.amazonaws.com

AWSTemplateFormatVersion: '2010-09-09' Description: | Example HTTP API with a JWT authorizer. This template includes an Amazon Cognito user pool as the issuer for the JWT authorizer and an Amazon Cognito app client as the audience for the authorizer. The outputs include a URL for an Amazon Cognito hosted UI where clients can sign up and sign in to receive a JWT. After a client signs in, the client is redirected to your HTTP API with an access token in the URL. To invoke the API with the access token, change the '#' in the URL to a '?' to use the token as a query string parameter. Resources: MyAPI: Type: AWS::ApiGatewayV2::Api Properties: Description: Example HTTP API Name: api-with-auth ProtocolType: HTTP Target: !GetAtt MyLambdaFunction.Arn DefaultRouteOverrides: Type: AWS::ApiGatewayV2::ApiGatewayManagedOverrides Properties: ApiId: !Ref MyAPI Route: AuthorizationType: JWT AuthorizerId: !Ref JWTAuthorizer JWTAuthorizer: Type: AWS::ApiGatewayV2::Authorizer Properties: ApiId: !Ref MyAPI AuthorizerType: JWT IdentitySource: - '$request.querystring.access_token' JwtConfiguration: Audience: - !Ref AppClient Issuer: !Sub https://cognito-idp.${AWS::Region}.amazonaws.com/${UserPool} Name: test-jwt-authorizer MyLambdaFunction: Type: AWS::Lambda::Function Properties: Runtime: nodejs18.x Role: !GetAtt FunctionExecutionRole.Arn Handler: index.handler Code: ZipFile: | exports.handler = async (event) => { const response = { statusCode: 200, body: JSON.stringify('Hello from the ' + event.routeKey + ' route!'), }; return response; }; APIInvokeLambdaPermission: Type: AWS::Lambda::Permission Properties: FunctionName: !Ref MyLambdaFunction Action: lambda:InvokeFunction Principal: apigateway.amazonaws.com SourceArn: !Sub arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${MyAPI}/$default/$default FunctionExecutionRole: Type: AWS::IAM::Role Properties: AssumeRolePolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Principal: Service: - lambda.amazonaws.com Action: - 'sts:AssumeRole' ManagedPolicyArns: - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole UserPool: Type: AWS::Cognito::UserPool Properties: UserPoolName: http-api-user-pool AutoVerifiedAttributes: - email Schema: - Name: name AttributeDataType: String Mutable: true Required: true - Name: email AttributeDataType: String Mutable: false Required: true AppClient: Type: AWS::Cognito::UserPoolClient Properties: AllowedOAuthFlows: - implicit AllowedOAuthScopes: - aws.cognito.signin.user.admin - email - openid - profile AllowedOAuthFlowsUserPoolClient: true ClientName: api-app-client CallbackURLs: - !Sub https://${MyAPI}.execute-api.${AWS::Region}.amazonaws.com ExplicitAuthFlows: - ALLOW_USER_PASSWORD_AUTH - ALLOW_REFRESH_TOKEN_AUTH UserPoolId: !Ref UserPool SupportedIdentityProviders: - COGNITO HostedUI: Type: AWS::Cognito::UserPoolDomain Properties: Domain: !Join - '-' - - !Ref MyAPI - !Ref AppClient UserPoolId: !Ref UserPool Outputs: SignupURL: Value: !Sub https://${HostedUI}.auth.${AWS::Region}.amazoncognito.com/login?client_id=${AppClient}&response_type=token&scope=email+profile&redirect_uri=https://${MyAPI}.execute-api.${AWS::Region}.amazonaws.com

CLI를 사용하여 JWT 권한 부여자를 사용하도록 경로 업데이트

콘솔, AWS CLI, 또는 AWS SDK를 사용하여 JWT 권한 부여자를 사용하도록 경로를 업데이트할 수 있습니다.

콘솔을 사용하여 JWT 권한 부여자를 사용하도록 경로 업데이트

다음 단계는 콘솔을 사용하여 JWT 권한 부여자를 사용하도록 경로를 업데이트하는 방법을 보여줍니다.

콘솔을 사용하여 JWT 권한 부여자를 생성하는 경우
  1. https://console.aws.amazon.com/apigateway에서 API Gateway 콘솔에 로그인합니다.

  2. HTTP API를 선택합니다.

  3. 기본 탐색 창에서 권한 부여자를 선택합니다.

  4. 방법을 선택한 다음 드롭다운 메뉴에서 권한 부여자를 선택하고 권한 부여자을 선택합니다.

AWS CLI를 사용하여 JWT 권한 부여자를 사용하도록 경로 업데이트

다음 update-route 명령은 JWT 권한 부여자를 사용하도록 경로를 업데이트합니다.

aws apigatewayv2 update-route \ --api-id api-id \ --route-id route-id \ --authorization-type JWT \ --authorizer-id authorizer-id \ --authorization-scopes user.email
프라이버시사이트 이용 약관쿠키 기본 설정
© 2025, Amazon Web Services, Inc. 또는 계열사. All rights reserved.