代码之家  ›  专栏  ›  技术社区  ›  Thomas Jørgensen

使用cognito和c无服务器应用程序

  •  1
  • Thomas Jørgensen  · 技术社区  · 7 年前

    AWS Serverless Application with Tests (.NET Core)

    我在AWS Cognito中创建了一个用户池,以及一个允许用户使用AWS Cognito登录的JavaScript客户机(单页应用程序)。在JavaScript客户机中,我能够连接到AWS Cognito,并以JWT的形式获取ID、访问和刷新令牌。我也可以用 Authorization: Bearer eyblablabla...

    我的问题是:后端似乎不知道授权头。在检查请求时,我没有得到任何用户的声明。我特别感兴趣的是 sub Unauthorized

    作为lambda函数签名的一部分,我得到 APIGatewayProxyRequest request.RequestContext.Authorizer.Claims .Authorizer 为空。

    不会被填充。

    serverless.yml 或Swagger模板文件,两者都不是AWS Serverless应用程序VS2017模板的一部分。相反,我有一个 serverless.template

    任何帮助都将不胜感激。

    1 回复  |  直到 6 年前
        1
  •  0
  •   mfierro    6 年前

    {
    "Resource": "/test",
    "Path": "/test",
    "HttpMethod": "GET",
    "Headers": {
        "Accept": "*/*",
        "accept-encoding": "gzip, deflate",
        "Authorization": "your token",
        "cache-control": "no-cache",
        "CloudFront-Forwarded-Proto": "https",
        "CloudFront-Is-Desktop-Viewer": "true",
        "CloudFront-Is-Mobile-Viewer": "false",
        "CloudFront-Is-SmartTV-Viewer": "false",
        "CloudFront-Is-Tablet-Viewer": "false",
        "CloudFront-Viewer-Country": "US",
        "Host": "xxxxxxx.execute-api.us-east-1.amazonaws.com",
        "Postman-Token": "08820d50-c5d4-498a-bfee-c76994bb91f1",
        "User-Agent": "PostmanRuntime/7.4.0",
        "Via": "1.1 dd169cfdbbafbb3da513bede6bc6640e.cloudfront.net (CloudFront)",
        "X-Amz-Cf-Id": "89ftx9aaVK0k2KOFu-5QESLXzGUGAw17gNCCY03in-hF2hd-LvRhIg==",
        "X-Amzn-Trace-Id": "Root=1-5c125bb9-1e8b9fea8d1beb20147a24d2",
        "X-Forwarded-For": "50.196.109.21, 70.132.33.133",
        "X-Forwarded-Port": "443",
        "X-Forwarded-Proto": "https"
    },
    "QueryStringParameters": null,
    "PathParameters": null,
    "StageVariables": null,
    "RequestContext": {
        "Path": "/test_oauth/token",
        "AccountId": "xxxxxxxxxxxxx",
        "ResourceId": "luy67k",
        "Stage": "test_oauth",
        "RequestId": "5455133d-fed9-11e8-8f41-ef35907ced2d",
        "Identity": {
            "CognitoIdentityPoolId": null,
            "AccountId": null,
            "CognitoIdentityId": null,
            "Caller": null,
            "ApiKey": null,
            "SourceIp": "50.196.109.21",
            "CognitoAuthenticationType": null,
            "CognitoAuthenticationProvider": null,
            "UserArn": null,
            "UserAgent": "PostmanRuntime/7.4.0",
            "User": null
        },
        "ResourcePath": "/token",
        "HttpMethod": "GET",
        "ApiId": "8xxg9ez961",
        "Authorizer": {
            "claims": {
                "sub": "4560ac4b-54a0-4184-8831-e3cb2583726b",
                "aud": "xxxxxxxxxxxxxxxx",
                "email_verified": "false",
                "event_id": "467633ad-fed9-11e8-88ff-25be6cd15697",
                "token_use": "id",
                "custom:ApplicationId": "12345",
                "auth_time": "1544706978",
                "iss": "https://cognito-idp.us-east-1.amazonaws.com/us-east-xxxxxxxxx",
                "cognito:username": "username",
                "exp": "Thu Dec 13 14:16:18 UTC 2018",
                "iat": "Thu Dec 13 13:16:18 UTC 2018",
                "email": "user@email.com"
            }
        }
    },
    "Body": null,
    "IsBase64Encoded": false
    }