facebook / facebook-ios-sdk

Used to integrate the Facebook Platform with your iOS & tvOS apps.
https://developers.facebook.com/docs/ios
Other
7.8k stars 3.56k forks source link

Getting Invalid Signature while validaing Facebook Limited Login's JWT #2416

Open Jay21022001 opened 6 months ago

Jay21022001 commented 6 months ago

Checklist before submitting a bug report

Xcode version

1.1.1

Facebook iOS SDK version

17.0.1

Dependency Manager

Other / I don't know

SDK Framework

Login

Goals

While Verifying Facebook Limited Login JWT, The Signature should be verified, But It throws "invalid signature" Error

Expected results

The Signature should be verified successfully

Actual results

It throws an "Invalid Signature" Error

Error: invalid signature

Steps to reproduce

  1. Pass your nonce and get the JWT from the Facebook
  2. Call the Facebook's JWKS and get your Public key
  3. Verify the signature => It throws an Invalid Signature

Code samples & details

const decoded = jwt.decode(token, { complete: true });
const { kid, alg } = decoded.header;
const key = await this.getPublicKey(kid);
const signingKey = key.getPublicKey();
console.log(signingKey)
return jwt.verify(token, signingKey, {
    algorithms: [alg],
});

static async getPublicKey(kid) {
    const client = jwksClient({
    jwksUri: FACEBOOK_JWKS_URL,
    timeout: API_TIMEOUT
    });
    return client.getSigningKey(kid);
}
Jay21022001 commented 5 months ago

Anyone, Please help me with this issue.

JuanEBrainium commented 5 months ago

We are also experiencing this issue

shkfaiz commented 4 months ago

Anyone found the fix

akrin-0 commented 2 months ago

Hello, I was looking for a solution to the same problem, what I realized is that there was no problem at the first place. Check this out: https://github.com/facebook/facebook-ios-sdk/issues/2442#issuecomment-2221223725