【问题标题】:Set User Pool 'App Client Id' as audience for HTTP API AWS YAML - token does not have a valid audience将用户池“应用程序客户端 ID”设置为 HTTP API AWS YAML 的受众 - 令牌没有有效的受众
【发布时间】:2020-04-28 23:16:21
【问题描述】:

您如何通过将正确的受众添加到 aws 授权方来解决 token does not have a valid audience

一旦我使用带有有效 JWT 的 Authorization 标头,yaml 配置中的以下 sn-p 将返回 token does not have a valid audience

Auth:
  DefaultAuthorizer: JwtAuthentication
  Authorizers:
    JwtAuthentication:
      IdentitySource: $request.header.Authorization
      JwtConfiguration:
        audience:
          - my-audience
        issuer: !Sub https://cognito-idp.${AWS::Region}.amazonaws.com/${OperationsUserPool}

【问题讨论】:

    标签: oauth-2.0 amazon-cognito serverless aws-sam


    【解决方案1】:

    一旦我解码了我的 lambda 生成的 JWT

    const login = await cognitoidentityserviceprovider
            .adminInitiateAuth(params)
            .promise();
    

    我注意到audienceApp Client Id,但不知道如何获得audience 所以原来它是RefAWS::Cognito::UserPoolClient

    您可以在此处找到更多信息 https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cognito-userpoolclient.html#cfn-cognito-userpoolclient-allowedoauthflowsuserpoolclient

    Auth:
      DefaultAuthorizer: JwtAuthentication
      Authorizers:
        JwtAuthentication:
          IdentitySource: $request.header.Authorization
          JwtConfiguration:
            audience:
              - !Ref OperationsUserPoolClient
            issuer: !Sub https://cognito-idp.${AWS::Region}.amazonaws.com/${OperationsUserPool}
    

    希望这对某人有所帮助!

    【讨论】:

      猜你喜欢
      • 2022-08-17
      • 2015-11-07
      • 2021-02-18
      • 2023-03-25
      • 2018-11-15
      • 2019-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多