Failed to Log In

I used Plug and Play swift SDK… And the code has been working for weeks.

But suddenly today, when my server tries to verify the token, it throws error.

Swift code:

web3Auth = await Web3Auth(.init(clientId: clientID, network: network, buildEnv: buildEnv, useCoreKitKey: useCoreKit))
try await web3Auth?.login(W3ALoginParams(loginProvider: provider, mfaLevel: .NONE))
idToken = try web3Auth?.getUserInfo().idToken

Then client will pass up idToken to server.

Then on server:

// Get the JWK set used to sign the JWT issued by Web3Auth
 const jwks = jose.createRemoteJWKSet(new URL("https://api-auth.web3auth.io/jwks"))

 // Verify the JWT using Web3Auth's JWKS
 let publicKey
 try {
    const jwtDecoded = await jose.jwtVerify(idToken, jwks, { algorithms: ["ES256"] })
    console.log(jwtDecoded)
    publicKey = (jwtDecoded.payload as any).wallets[0].public_key
} catch (err) {
    console.log(err)
  }

Server side produced the error:

JWKSNoMatchingKey: no applicable key found in the JSON Web Key Set
    at RemoteJWKSet.getKey (.../node_modules/jose/dist/node/cjs/jwks/local.js:85:19)
    at RemoteJWKSet.getKey (.../node_modules/jose/dist/node/cjs/jwks/remote.js:55:32)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async flattenedVerify (.../node_modules/jose/dist/node/cjs/jws/flattened/verify.js:75:15)
    at async compactVerify (.../node_modules/jose/dist/node/cjs/jws/compact/verify.js:18:22)
    at async Object.jwtVerify (.../node_modules/jose/dist/node/cjs/jwt/verify.js:8:22) {
  code: 'ERR_JWKS_NO_MATCHING_KEY'
}

Please help me on what I should do here?

The code has been working for a couple of weeks. So it won’t be because the client side token expiry issue (the token expiry is 1 day according to web3auth)…

@zhew1991 Your issue is under review and will get back with further updates.

The key in the JWT does not match the key in JWKS.
Can you generate a new token and give it a try?

To generate on the client side, right?

So I have tried to uninstall my app and reinstall (this will wipe out old tokens on client), and still my server says the token is invalid.

Also, is my server side code algorithms: ["ES256"] correct?

Does that match up with the Swift Play n Play SDK’s id token generation?

I don’t have any clue on what is going on. Thanks!

I will forward your issue to our dev team and get back with further updates.

Thank you!

I am totally blocked now.

Hello, after checking your token, it seems to be generated using buildEnv: "testing" of web3auth.
pls check your build environment in code once again.

It works now after I change the buildEnv to production. Thank you!!!

But I am curious that used to be working before yesterday. What has changed that cause this?

Nothing else change in my code (on server and client).

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.