-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for multiple apple public keys #8
base: master
Are you sure you want to change the base?
Add support for multiple apple public keys #8
Conversation
Currently we use only first public key provided by apple to verify ID token. It seems that apple issues ID tokens with different keys (3 in this moment). This fix uses `header.kid` field from ID token in order to identify which public key will be used to verify ID token.
source/index.js
Outdated
const data = await request({ url: url.toString(), method: 'GET' }); | ||
const key = JSON.parse(data).keys[0]; | ||
const key = JSON.parse(data).keys.find(key => key.kid === kid); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
request-promise-native
accepts a json
option to automatically parse the response as json.
Can be written as the following for a small gain in readability
const keys = await request({ url: url.toString(), method: 'GET', json: true });
const key = keys.find(k => k.kid === kid);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch! Pull request is updated.
Can we move the discussion in #9 ? IMO, it would be good to move to |
@alexabidri I applied your suggestion to this PR. I hope this is ok. |
@tomislavherman Good job! Personnaly I would prefer to use As apple-signin is a package aim to be used by some startup/corporations, I would avoid using a non maintained module which doesnt provide big improvements except to promisify a already existing module. Some hours ago, jwks-rsa got a new release (1.7.0) Here is a simple wrapper to promisified
|
Thanks, @alexabidri. I agree with you regarding the I would just instantiate jwks client in the scope of the module instead of in the scope of |
Create wrapper around client which promisifies getSigningKey on jwks client
Currently we use only first public key provided by apple to verify ID
token. It seems that apple issues ID tokens with different keys (3 in
this moment). This fix uses
header.kid
field from ID token in order toidentify which public key will be used to verify ID token.