我们在 API 网关中为 Auth0 配置了一个自定义授权方。我们希望它根据调用它的阶段加载不同的配置值。有已知的方法来处理这个问题吗?
最佳答案
你有两个选择:
如果您想在两个阶段使用相同的授权方函数,您可以解析 input passed to the function其中包括舞台:
{ "type":"TOKEN", "authorizationToken":"<caller-supplied-token>", "methodArn":"arn:aws:execute-api:<regionId>:<accountId>:<apiId>/<stage>/<method>/<resourcePath>" }
如果您想在每个阶段使用不同的函数,您可以使用阶段变量。 注意:您必须使用 CLI 或 SDK 添加带有阶段变量的授权方。 CLI 示例:
aws apigateway update-authorizer --rest-api-id <apidId> --authorizer-id <authorizerId> --patch-operations '[{"op":"replace","path":"/authorizerUri","value":"arn:aws:apigateway:<region>:lambda:path/2015-03-31/functions/arn:aws:lambda:<region>:<accountId>:function:${stageVaribles.authorizer}/invocations"}]'
关于amazon-web-services - 自定义授权者 + 阶段配置值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38469633/