AWS Cognito Identity authenticateUser 호출에서 가져온 사용자의 IDToken을 확인하는 방법을 알아 내려고하고 있습니다.AWS Cognito JWT IDToken이 njwt가있는 JWK 세트에 대해
여기에 나와있는 단계를 수행하면 다음과 같습니다. https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-using-tokens-with-identity-providers.html#amazon-cognito-identity-user-pools-using-id-and-access-tokens-in-web-api 사용자 ID Token이있는 지점에 도달 할 수 있었으며 헤더와 본문을 디코딩했습니다.
가 IDToken을 감안할 때이 내 헤더와 본문이 어떻게 생겼는지입니다 :
헤더 :
{
typ: 'JWT',
alg: 'RS256',
kid: '...'
}
몸 :
{
sub: 'abcd...',
aud: 'abcdefg...',
email_verified: true,
token_use: 'id',
auth_time: 1491491773,
iss: 'https://cognito-idp.us-east-1.amazonaws.com/us-east-...',
'cognito:username': 'username',
exp: 1491495373,
iat: 1491491773,
email: '[email protected]'
}
는 그 다음 IDToken의 세 번째 부분은 서명입니다 :
'T6tjQ...' // big long encoded string
내가 붙어있는 부분은 실제로 서명 키에 대한 서명을 확인하는 것입니다. 이 부분이 작동하지 않는 것 같습니다. 지금은 https://www.npmjs.com/package/njwt 노드 모듈 njwt
을 사용하려고합니다. 다음과 같은 자바 스크립트 객체로
을 감안할 때 3 부분 .
분리 base64로 인코딩 된 문자열로 IDToken
및 secretKey
는 :
njwt.verify(IDToken, secretKey, 'RS256', function(err, verifiedJwt)
{
if (err)
{
console.log(err);
}
else
{
console.log('Verified');
}
});
:
{
alg: 'RS256',
e: '...',
kid: '...', // matches kid of IDToken
kty: 'RSA',
n: 'abcdefg...', // Appears to be some big long encoded string
use: 'sig'
}
이 내가 njwt
노드 모듈을 시도한 것입니다
이렇게하면 다음과 같은 결과를 얻을 수 있습니다.
TypeError: Not a buffer
at Verify.verify (crypto.js:426:24)
at .../node_modules/njwt/index.js:406:10
at Verifier.defaultKeyResolver (.../node_modules/njwt/index.js:72:10)
at Verifier.verify (.../node_modules/njwt/index.js:375:15)
at Object.jwtLib.verify (.../node_modules/njwt/index.js:457:21)
at repl:1:6
at REPLServer.self.eval (repl.js:110:21)
at repl.js:249:20
at REPLServer.self.eval (repl.js:122:7)
at Interface.<anonymous> (repl.js:239:12)
01 나는 그것을 내가 할이 방법을 시도 할 때
njwt.verify(IDToken, secretKey.n, 'RS256', function(err, verifiedJwt)
{
if (err)
{
console.log(err);
}
else
{
console.log('Verified');
}
});
을 :
139980866705216:error:0906D06C:PEM routines:PEM_read_bio:no start line:pem_lib.c:696:Expecting: CERTIFICATE
내
console.log(err);
얹는 : 23,516,
그래서 난과 같이 secretKey.n
대신 secretKey
에 전달해야 어쩌면 생각
{ [JwtParseError: Signature verification failed]
name: 'JwtParseError',
userMessage: 'Signature verification failed',
message: 'Signature verification failed',
jwtString: 'abcdefg...',
parsedHeader: {
typ: 'JWT',
alg: 'RS256',
kid: '...'
},
parsedBody: {
sub: 'abcd...',
aud: 'abcdefg...',
email_verified: true,
token_use: 'id',
auth_time: 1491491773,
iss: 'https://cognito-idp.us-east-1.amazonaws.com/us-east-...',
'cognito:username': 'username',
exp: 1491495373,
iat: 1491491773,
email: '[email protected]'
},
innerError: undefined }
secretKey
은 어떻게 전달해야합니까? secretKey
은 무엇이며 어떻게해야합니까? 상당히 정직하기를 나는 심지어 무엇이 njwt.verify
을 기대하고 있는지 잘 모르겠다.