-
Notifications
You must be signed in to change notification settings - Fork 14
feat: support client assertion for client credentials authentication #228
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
base: main
Are you sure you want to change the base?
Conversation
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #228 +/- ##
==========================================
- Coverage 88.18% 88.16% -0.02%
==========================================
Files 23 23
Lines 1202 1217 +15
Branches 211 197 -14
==========================================
+ Hits 1060 1073 +13
- Misses 84 86 +2
Partials 58 58 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
.setExpirationTime("2m") | ||
.sign(privateKey); | ||
return { | ||
...config.customClaims, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I chose to spread config.customClaims
first so that any of the required properties will be set, however I can also see a world where it might be desirable to allow this to be overridden.
.setSubject(config.clientId) | ||
.setJti(randomUUID()) | ||
.setIssuer(config.clientId) | ||
.setAudience(`https://${config.apiTokenIssuer}/`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might seem unexpected, but per the spec the aud
in this JWT assertion must identify the authorization server as it is the intended consumer of the JWT
/** | ||
* Client Secret | ||
* | ||
* @type {string} | ||
* @memberof Configuration | ||
*/ | ||
clientSecret: string; | ||
|
||
} | ||
export type ClientAssertionConfig = BaseClientCredentialsConfig & { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering whether to rename the config as that PrivateKeyJWT
is the authentication type and ClientAssertion
is just the property it is sent as (although I think it should remain clientAssertionSigningKey
and clientAssertionSigningAlgorithm
export type ClientAssertionConfig = BaseClientCredentialsConfig & { | |
export type PrivateKeyJWTConfig = BaseClientCredentialsConfig & { |
Description
This PR introduces support for performing a client credentials authentication flow using client assertion (aka private key jwt, jwt ca) as an alternative to the existing client secret authentication method.
As this is an alternative
ClientCredentials
method I have split the existing configuration out intoClientSecretConfig
and introduced aClientAssertionConfig
to go along side this and changed theClientCredentialsConfig
to be union of the two to allow type checking to work correctly.The client assertion signing is performed using jose and I am using v5 of this library over v6 as the latter is an ESM only package which would have implications for our supported Node.js versions.
An extra, not insignificant change to this is the addition of a
customClaims
property on the client credentials configuration, this is to allow extra data to be passed to the token exchange for clients that need this.References
Review Checklist
main