我正在使用AWS Cognito对用户进行身份验证。
我使用Kosjs创建了一个服务器,并使用koa-jwt库来验证用户是否具有有效的id_tokens。
koa-jwt在id_token中期望有一个 aud 属性,该属性最初存在于AWS Cognito返回的id_token中。
但是当我使用刷新令牌获取新令牌时,新令牌包含 client_id 而不是 aud 。
因此,koa-jwt不再验证id_token。
是否可以通过AWS Cognito获得一致的结果?
这是登录后的示例id_token:
{
"sub": "1Xfe6c44-XXXX-4cbf-9fb2-2778a1b0e5be",
"email_verified": true,
"iss": "https://cognito-idp.ap-northeast-1.amazonaws.com/ap-northeast-1_xxxOUKTJu",
"phone_number_verified": true,
"cognito:username": "oqtz@n.spamtrap.co",
"given_name": "Some1",
"aud": "xxxxf9f0lmr1q6ni2c09umdds",
"event_id": "9cf03730-xxxx-11e9-a89f-67080ff7c936",
"token_use": "id",
"auth_time": 1546931916,
"phone_number": "+16806666986",
"exp": 1546935516,
"iat": 1546931916,
"family_name": "Some2",
"email": "oqtz@n.spamtrap.co"
}
这是refresh_token返回的示例id_token:
{
"sub": "16fe6c44-xxxx-xxxx-9fb2-2778a1b0e5be",
"event_id": "9cf03730-xxxx-xxxx-a89f-67080ff7c936",
"token_use": "access",
"scope": "aws.cognito.signin.user.admin",
"auth_time": 1546931916,
"iss": "https://cognito-idp.ap-northeast-1.amazonaws.com/ap-northeast-1_xxxxxKTJu",
"exp": 1546939290,
"iat": 1546935690,
"jti": "6fab7b58-xxxx-xxxx-a339-ddb6467e2d4c",
"client_id": "xxxxx9f0lmr1q6ni2c09umdds",
"username": "oqtz@n.spamtrap.co"
}
答案 0 :(得分:0)
我还没有对刷新进行全面的测试,但是通过遵循koa-jwt自述文件this section底部的示例,我可以快速地进行基础操作。
const { koaJwtSecret } = require('jwks-rsa');
app.use(jwt({
secret: <any> koaJwtSecret({
jwksUri: `https://cognito-idp.${config.userPoolRegion}.amazonaws.com/${config.userPoolId}/.well-known/jwks.json`,
cache: true,
cacheMaxEntries: 5,
cacheMaxAge: 36000000 ///10 hr
})
}));