question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unexpected JWT alg received, expected HS256, got: RS256

See original GitHub issue

I am having issues using HS256 signing algorithm:

BadRequestError: unexpected JWT alg received, expected HS256, got: RS256 at /<project-path>/node_modules/express-openid-connect/middleware/auth.js:121:19 at runMicrotasks () at processTicksAndRejections (internal/process/task_queues.js:95:5)

server.js

  app.use(
    auth({
      authRequired: true,
      idpLogout: true,
      idTokenSigningAlg: 'HS256',
      issuerBaseURL: process.env.ISSUER_BASE_URL,
      clientID: process.env.CLIENT_ID,
      authorizationParams: {
        response_type: "code",
        audience: process.env.AUDIENCE,
        scope: "openid profile email",
      },
    })
  );

.env

CLIENT_ID=Kr***********************WhTI
BASE_URL=http://localhost:3000
CLIENT_SECRET=wd************************************************tRLg99
AUDIENCE=https://my-audience
SECRET=0y************************ySlx
ISSUER_BASE_URL=https://mydomain.auth0.com
PORT=3000

Dependencies:

    "express": "4.18.1",
    "express-openid-connect": "2.8.0",
    "express-session": "^1.17.3",

– node v14.17.6

Am I missing something?

I also added a console.log in /node_modules/express-openid-connect/middleware/auth.js to print client object, and I got:

Client {
  authorization_signed_response_alg: 'RS256',
  client_id: 'Kr**********************hTI',
  client_secret: 'wdj***************************************RLg99',
  grant_types: [
    'authorization_code'
  ],
  id_token_signed_response_alg: 'HS256',
  response_types: [
    'code'
  ],
  revocation_endpoint_auth_method: 'client_secret_basic',
  token_endpoint_auth_method: 'client_secret_basic'
}

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
adamjmcgrathcommented, Jul 27, 2022

OK, Thanks for sharing that

For the purposes of this SDK, you should use Regular Web Application - which will resolve this issue for you, so closing

But I’ll be sure to follow up with the relevant teams offline to resolve the issue you’ve discovered

0reactions
lissettdmcommented, Jul 27, 2022

Hi @lissettdm - could you share how you were able to create a “Single Page Application” app with ID Token Signing Alg set to HS256?

@adamjmcgrath This is what I did (Application was already created as SPA with signing algorithm RS256). To change signing algorithm I went to

  • Application Settings -> Advanced Settings -> Oauth
  • OIDC Conformant is active and JSON Web Token (JWT) Signature Algorithm dropdown is disabled
Screen Shot 2022-07-27 at 09 25 17
  • Deactivate OIDC Conformant option
  • JSON Web Token (JWT) Signature Algorithm dropdown is enable and you can switch between option Screen Shot 2022-07-27 at 09 26 26
Read more comments on GitHub >

github_iconTop Results From Across the Web

unexpected JWT alg received, expected HS256, got: RS256
I am trying to use express-openid-connect: 2.7.3 with HSHS256 signing algorithm. I am getting this error: BadRequestError: unexpected JWT ...
Read more >
"failed to validate JWT signature" #21 - auth0/nextjs ... - GitHub
Mine was originally set to RS256 , I changed it to HS256 just to double check and got unexpected JWT alg received, expected...
Read more >
express-openid-connect: unexpected JWT alg received ...
I am using express-openid-connect:2.8.0 with HS256 signing algorithm: server.js app.use( auth({ authRequired: true, idpLogout: true, ...
Read more >
Usage Examples — PyJWT 2.6.0 documentation
Encoding & Decoding Tokens with RS256 (RSA)​​ If you are repeatedly encoding with the same private key, reusing the same RSAPrivateKey also has...
Read more >
IDTokenValidator rejects alg=HS256 kid=xxx JWT ... - Bitbucket
The error message that you're getting is indeed symptomatic of trying to do HS256 validation where an RSxxx alg (e.g. RS256) is expected...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found