Skip to content

Add support for client assertion signing key authentication - #203

Merged
arpit-jn merged 1 commit into
auth0:masterfrom
kaczowkad:support_private_key_jwt
May 12, 2026
Merged

arpit-jn merged 1 commit into
auth0:masterfrom
kaczowkad:support_private_key_jwt

Conversation

@kaczowkad

Copy link
Copy Markdown
Contributor

Changes

The omniauth-auth0 gem only supports client secret authentication. Auth0 documentation states:

To ​​improve your security posture, we recommend using the Private Key JWT authentication method.

Opened issue #199 on 2024-11-07 to inquire about adding support for private key JWT authentication. We created a workaround to support private key JWT authentication in our application using the omniauth-auth0 gem. Opening this PR to get feedback on adding support for private key JWT added to the gem.

This PR adds two optional parameters to the config:

  • client_assertion_signing_key - the private key
  • client_assertion_signing_algorithm - algorithm defaults to RS256

The current interface is preserved. Client secret authentication can be used without changing the interface.

Client secret authentication:

AUTH0_CONFIG = Rails.application.config_for(:auth0)

Rails.application.config.middleware.use OmniAuth::Builder do
  provider(
    :auth0,
    AUTH0_CONFIG['auth0_client_id'],
    AUTH0_CONFIG['auth0_client_secret'],
    AUTH0_CONFIG['auth0_domain'],
    callback_path: '/auth/auth0/callback',
    authorize_params: {
      scope: 'openid profile'
    }
  )
end

Client assertion signing key:

AUTH0_CONFIG = Rails.application.config_for(:auth0)

Rails.application.config.middleware.use OmniAuth::Builder do
  provider(
    :auth0,
    AUTH0_CONFIG['auth0_client_id'],
    nil,
    AUTH0_CONFIG['auth0_domain'],
    callback_path: '/auth/auth0/callback',
    authorize_params: {
      scope: 'openid profile'
    }
    client_assertion_signing_key: AUTH0_CONFIG[:auth0_client_assertion_signing_key],
    client_assertion_signing_algorithm: AUTH0_CONFIG[:auth0_client_assertion_signing_algorithm]}
  )
end

The existing code has rubocop violations which were not addressed because it was outside the scope of these changes. No new rubocop violations were introduced.

References

Please include relevant links supporting this change such as a:

Testing

Duplicated all the specs in spec/omniauth/strategies/auth0_spec.rb for client assertion signing key. The existing specs were scoped to 'client secret authentication'. All specs passed.

Testing with Auth0 requires an application setup for private key JWT authentication. The public key must be uploaded to the application in Auth0.

  • This change adds unit test coverage
  • This change has been tested on the latest version of the platform/language or why not
    Tested with ruby 3.2.2. Built the gem and client assertion signing key authentication with a Ruby on Rails application.

Checklist

@kaczowkad
kaczowkad requested a review from a team as a code owner June 20, 2025 19:57
Comment thread README.md Resolved
Comment thread README.md Resolved
Comment thread README.md Resolved
Comment thread lib/omniauth/auth0/jwt_token.rb Resolved
Comment thread lib/omniauth/auth0/jwt_token.rb Resolved
Comment thread lib/omniauth/strategies/auth0.rb Resolved
Comment thread spec/omniauth/auth0/jwt_token_spec.rb Resolved
let(:domain_url) { 'https://samples.auth0.com' }
let(:client_assertion_signing_algorithm) { 'RS256' }
let(:client_assertion_signing_key) { OpenSSL::PKey::RSA.new(2048) }
let(:application) do

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: The existing codebase uses OpenSSL::PKey::RSA.generate(2048) (see jwt_token_spec.rb line 10). .new(2048) works but is deprecated in newer OpenSSL versions. Use .generate for consistency.

Comment thread spec/omniauth/strategies/auth0_spec.rb Resolved
Comment thread spec/omniauth/strategies/auth0_spec.rb Resolved
@arpit-jn

Copy link
Copy Markdown
Contributor

Thanks for the contribution @kaczowkad this is a much-needed feature and the overall approach is solid. Apologies for the delay in reviewing this. I know this PR has been open for a while, and I appreciate your patience.

I've left detailed inline feedback across the files. The main themes are:

  1. Bugs: syntax error in README example, audience in token params will break flows, missing require statements, and auth_scheme: :private_key_jwt not recognized by oauth2 1.x
  2. Compatibility: Ruby 3.1+ hash shorthand will break older Rubies, jwt gem needs to be a runtime dependency
  3. Spec quality: heavy duplication could be reduced with shared_examples

Also, please ensure all commits are GPG-signed. Commit 802638a is currently unsigned. You can either:

  • Amend and force-push with signing enabled (git commit --amend -S)
  • Or squash into a new signed commit

See GitHub's guide on signing commits if you need help setting that up.

Looking forward to the next iteration. 🙌

@kaczowkad

Copy link
Copy Markdown
Contributor Author

@arpit-jn Thank you for the feedback. I will try to have the updates later this week.

@kaczowkad
kaczowkad force-pushed the support_private_key_jwt branch 2 times, most recently from c859896 to 902cf4c Compare April 24, 2026 21:36
@kaczowkad
kaczowkad requested a review from arpit-jn April 24, 2026 21:43
@arpit-jn

arpit-jn commented May 8, 2026

Copy link
Copy Markdown
Contributor

Hey @kaczowkad, thanks for the updates, nearly everything from the review is addressed. Two remaining items before we can merge:

1. CI is failing on Ruby 3.0: there's one remaining Ruby 3.1+ hash shorthand at spec/omniauth/strategies/auth0_spec.rb:590:

stub_auth(oauth_response.merge(refresh_token:))

Needs to be:
stub_auth(oauth_response.merge(refresh_token: refresh_token))

2. Commit signing: Both commits are currently unsigned. Could you squash into a single GPG-signed commit? Or let us know if you want us to take it forward.

Once those are done, we're good to merge. Let me know if you need help with either.

…tinuing to support client secret authentication.

The client assertion signing key allows Private Key JWT application authentication in Auth0.  The client_assertion_signing_key and client_assertion_signing_algorithm are optional parameters.
Client assercition signing key will be used if a client_assertion_signing_key is privided. The client_assertion_signing_algorithm is optional. The algorithm defaults to RS256 if nil or not
provided.
@kaczowkad
kaczowkad force-pushed the support_private_key_jwt branch from 902cf4c to 2b5d9ec Compare May 8, 2026 18:50
@kaczowkad

Copy link
Copy Markdown
Contributor Author

Hi @arpit-jn, The two issues you highlighted have been addressed. Sorry those were missed on the previous update. Thanks for the review.

@arpit-jn arpit-jn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread spec/omniauth/auth0/jwt_token_spec.rb Resolved
Comment thread README.md Resolved
Comment thread spec/omniauth/strategies/auth0_spec.rb Outdated
client_assertion_signing_key: client_assertion_signing_key,
client_assertion_signing_algorithm: client_assertion_signing_algorithm)
stub_jwt_token
stub_auth(oauth_response.merge(refresh_token:))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's one remaining Ruby 3.1+ hash shorthand at
stub_auth(oauth_response.merge(refresh_token:))

which should be
stub_auth(oauth_response.merge(refresh_token: refresh_token))

@arpit-jn
arpit-jn merged commit 3ebfb41 into auth0:master May 12, 2026
5 checks passed
@arpit-jn arpit-jn mentioned this pull request May 12, 2026
@PedroSena

Copy link
Copy Markdown

Sorry to use a closed issue for that but just wanted to double check something (probably not worth opening an issue about): Are the changes done here incompatible with jwt 3.x ?

Thanks

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

Successfully merging this pull request may close these issues.

3 participants