Skip to content
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

OAuth plugin does not grab key from JWK properly #88

Closed
jvlians opened this issue Oct 23, 2018 · 0 comments
Closed

OAuth plugin does not grab key from JWK properly #88

jvlians opened this issue Oct 23, 2018 · 0 comments

Comments

@jvlians
Copy link

jvlians commented Oct 23, 2018

The OAuth plugin in its current state fails to grab any valid JWK. The reason for this is that it evaluates the wrong property on the keys object. Here is the getJWK() function in its current state:

function getPEM(decodedToken, keys) {
    var i = 0;
    debug('jwk kid ' + decodedToken.headerObj.kid);
    for (; i < keys.length; i++) {
        if (keys.kid == decodedToken.headerObj.kid) {
            break;
        }
    }
    var publickey = rs.KEYUTIL.getKey(keys.keys[i]);
    return rs.KEYUTIL.getPEM(publickey);
}

Note how this function tries iterating over keys at its root, and accessing keys.kid, but keys is not iterable at its root, nor does it have any properties apart from keys. The structure of keys is (in my case) as follows:

{
    "keys": [
        {
            "kty": "RSA",
            "alg": "RS256",
            "kid": "99gMqQi7UIfDqij_JX_RoNkC-bU-vlGQGwXoKWbGoes",
            "use": "sig",
            "e": "AQAB",
            "n": "gDf_fZFQrmZw14aHvJWb2SaQ30XBzYqu40SRFBgGGg-2TGRJD5rKbehPWGfZpYw2UEp2-aYw2-pFzAJF4SfFo3IjsU2tM5kEFCUreJdDW0II7ZaGaxXFcyteX7ULGErdZkX8w98Zay8abOegJpsDr8UBgJ0wNIpXx_nEe_ttrj3XexJ9ximJkrHvg4X9_mYhghOO5BbernrjEkeZo1ioQj4Q_H-Cn-DUwODr9b6NJ46qvo1UrKij13Q4lNNftUgvRQy0wNCUUNNgAZpVJOruMS9DUdCv5MGjgVsW7_KLHfUj0-di19XSRrQHyK_wh22gqzUoPaj-rVmqzQ1itkELWw"
        },
        {
            "kty": "RSA",
            "alg": "RS256",
            "kid": "luIheUMdlhacSF0zk2-tNDA7qd3sns_l21arS59FX-8",
            "use": "sig",
            "e": "AQAB",
            "n": "xh8tmPpzytiEfmBOn1oA20hH2TSLTcRdZprXK4tKuWnhiBz__E_qGusFf8lAA9tN9BZM_YptLRd6fjKjbRv1D8XUEqgwQoUVI9oNK-WvaZL0ZT1AIzbP5wUN-5uxOhwczp-nQ_R7IYjED_v1snHQRNf4W-8295UzjdHwTr29cw2wdLDsnSvgtwpHd9zpcCXaFkQ6-g9M8OariL0jL7KPCUSpb1e9E-Swmq6af2E8Peq9B68Ecys2Jf1iw24oIncS-vg9ZGuq4F5MASKmLVDjbBIrU2lQ3muK6JrakKQYxqVMnaS6vR-U3bEp7CcuGo-sfRZTZT6RYusJSy2GNLutYw"
        }
    ]
}

Thus, the function should iterate over keys.keys, or keys should be populated by the keys object in this JSON object.

I've already submitted a PR that resolves this issue, and adds support for situations like https://www.googleapis.com/oauth2/v1/certs . This PR can be found here: #87

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants