gpt4 book ai didi

amazon-web-services - API 网关选项方法抛出 403

转载 作者:行者123 更新时间:2023-12-04 17:41:37 24 4
gpt4 key购买 nike

我有一个带有 API 网关Custom Authorizer。当通过 SAM 模块 部署时,它还会在您启用 CORS 时创建 Options Method。我真的不明白的是为什么自定义授权方附加到 Options 端点? enter image description here

当我尝试从浏览器调用端点时抛出 403 并且当我从 Options 方法中删除 Authorization 时工作正常。

enter image description here

下面是template.yaml

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'

Globals:
Function:
Runtime: nodejs8.10
Api:
Cors:
AllowMethods: "'*'"
AllowHeaders: "'*'"
AllowOrigin: "'*'"

Resources:
TestApi:
Type: AWS::Serverless::Api
Properties:
StageName: dev
Auth:
DefaultAuthorizer: testAuthoriser
Authorizers:
testAuthoriser:
FunctionArn:
Fn::ImportValue: !Sub test-custom-autoriser
Identity:
Header: Authorization
ValidationExpression: ^Bearer [-0-9a-zA-Z\._]*$
ReauthorizeEvery: 30

Version:
Type: 'AWS::Serverless::Function'
Properties:
FunctionName: test
CodeUri: src/test
Handler: index.test
Events:
EndPoint:
Type: Api
Properties:
RestApiId: !Ref TestApi
Path: /test
Method: get
Auth:
Authorizer: testAuthoriser

我也在 header 中启用了 'Access-Control-Allow-Origin': '*'。不确定这里发生了什么。任何帮助将不胜感激

最佳答案

答案在这里,请参阅 aws sam 问题 here

 Api:
Cors:
AllowHeaders: "'Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers, Authorization'"
AllowOrigin: "'*'"
Auth:
DefaultAuthorizer: CognitoAuthorizer
Authorizers:
CognitoAuthorizer:
UserPoolArn: yourUserPool
AddDefaultAuthorizerToCorsPreflight: False // <== this line

关于amazon-web-services - API 网关选项方法抛出 403,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54261625/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com