小编AHA*_*AHA的帖子

使用 API 密钥或授权方授权 AWS API Gateway

在 AWS API Gateway 中,
- 我们可以设置一个资源来请求 API Key 进行访问。
- 我们还可以设置另一个需要授权的资源(例如 JWT 令牌,通过 lambda 函数或 AWS Cognito 处理)。

问题:我们可以将资源配置为在上述两种情况中的任何一种情况下都可以访问吗?目前,如果我们同时启用“API Key Required”和“Authorization”,则请求同时需要 API Key 和 Authorization。我们希望它通过两者中的一个。

破解/解决方法:创建相同资源的两个副本,并分别授权每个副本,一个使用 API 密钥,另一个使用授权方。

api api-key amazon-web-services aws-api-gateway api-gateway

7
推荐指数
2
解决办法
1300
查看次数

ASP.Net中的JWT令牌异常(生命周期验证失败.令牌缺少过期时间.)

我在ASP上创建自己的自定义身份验证.Net Mobile部署在Azure上.我使用JWT令牌.以下是我生成新令牌的方法(claimType = email):

    public static string GetSecurityToken(String email)
    {
        var symmetricKey = Convert.FromBase64String(signingKey);
        var tokenHandler = new JwtSecurityTokenHandler();

        var now = DateTime.UtcNow;
        var tokenDescriptor = new SecurityTokenDescriptor
        {
            Subject = new ClaimsIdentity(new[]
                    {
                    new Claim(ClaimTypes.Email, email)
                }),
            NotBefore = now,
            Expires = now.AddYears(10),
            Issuer = issuer,
            Audience = audience,
            IssuedAt = now,
            SigningCredentials = new SigningCredentials(
                new SymmetricSecurityKey(symmetricKey),
                SecurityAlgorithms.HmacSha256Signature),
        };

        var stoken = tokenHandler.CreateToken(tokenDescriptor);
        var token = tokenHandler.WriteToken(stoken);

        return token;
    }
Run Code Online (Sandbox Code Playgroud)

令牌被发送到客户端并存储.但是当我尝试基于其令牌授权消息时,我收到错误:

终身验证失败.令牌缺少过期时间.

这是我尝试验证令牌的方式:

    public static ClaimsPrincipal GetPrincipal(string token) …
Run Code Online (Sandbox Code Playgroud)

asp.net authentication authorization lifetime jwt

5
推荐指数
2
解决办法
6550
查看次数