gpt4 book ai didi

swift - 无服务器和 alamofire "User is not authorized to access this resource"但与 postman 一起工作

转载 作者:行者123 更新时间:2023-11-28 13:35:57 24 4
gpt4 key购买 nike

我遇到了一个我无法解决的错误。仅通过 iOS (Alamofire) 从我的无服务器功能。我有大约 15 个函数,这只发生在两个函数上。其余功能运行良好。

{"Message":"User is not authorized to access this resource"}

当我使用 postman 时它工作正常。

我正在使用 token ,但所有其他功能都以相同的方式工作。它也不一定是无服务器权限错误,因为它是通过 postman 工作的。

这是基本的 Alamofire 代码。我正在为 header 使用请求适配器。

Alamofire
.request(url, method: method, parameters: params, encoding: JSONEncoding.default)
.validate(statusCode: 200..<500)
.validate(contentType: ["application/json"])

最佳答案

供以后引用:

我大概找到了答案。我现在没有时间深入挖掘。这与我的自定义身份验证功能的权限有关,即使它正在设置它也不允许特定的 Arn 通过。所以我现在所做的只是放置一个“*”,而不是函数的特定 arns。

const generatePolicy = (principalId, effect, resource) => {
const authResponse = {};
authResponse.principalId = principalId;
if (effect && resource) {
const policyDocument = {};
policyDocument.Version = "2012-10-17";
policyDocument.Statement = [];
const statementOne = {};
statementOne.Action = "execute-api:Invoke";
statementOne.Effect = effect;
statementOne.Resource = resource;
policyDocument.Statement[0] = statementOne;
authResponse.policyDocument = policyDocument;
}
return authResponse;
};

这样调用它

generatePolicy(val.id, "Allow", "*")

而不是传递 methodArn

const { authorizationToken, methodArn } = event;
generatePolicy(val.id, "Allow", methodArn)

不是最安全的,但我稍后会修复它。

关于swift - 无服务器和 alamofire "User is not authorized to access this resource"但与 postman 一起工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56623501/

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