-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for jwt-bearer client assertions in access token
- Loading branch information
Showing
8 changed files
with
125 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { AccessTokenRequest, AccessTokenRequestOpts, Jwt, OpenId4VCIVersion } from '@sphereon/oid4vci-common'; | ||
import { v4 } from 'uuid'; | ||
|
||
import { ProofOfPossessionBuilder } from '../ProofOfPossessionBuilder'; | ||
|
||
export const createJwtBearerClientAssertion = async ( | ||
request: Partial<AccessTokenRequest>, | ||
opts: AccessTokenRequestOpts & { | ||
version?: OpenId4VCIVersion; | ||
}, | ||
): Promise<void> => { | ||
const { asOpts } = opts; | ||
if (asOpts?.clientOpts?.clientAssertionType === 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer') { | ||
if (!request.client_id) { | ||
throw Error(`Not client_id supplied, but client-assertion jwt-bearer requested.`); | ||
} else if (!asOpts.clientOpts.kid) { | ||
throw Error(`No kid supplied, but client-assertion jwt-bearer requested.`); | ||
} else if (!asOpts.clientOpts.signCallbacks) { | ||
throw Error(`No sign callback supplied, but client-assertion jwt-bearer requested.`); | ||
} | ||
const jwt: Jwt = { | ||
header: { | ||
typ: 'JWT', | ||
kid: asOpts.clientOpts.kid, | ||
alg: asOpts.clientOpts.alg ?? 'ES256', | ||
}, | ||
payload: { | ||
iss: request.client_id, | ||
sub: request.client_id, | ||
aud: opts.credentialIssuer, | ||
jti: v4(), | ||
exp: Date.now() / 1000 + 60, | ||
iat: Date.now() / 1000 - 60, | ||
}, | ||
}; | ||
const pop = await ProofOfPossessionBuilder.fromJwt({ | ||
jwt, | ||
callbacks: asOpts.clientOpts.signCallbacks, | ||
version: opts.version ?? OpenId4VCIVersion.VER_1_0_13, | ||
mode: 'jwt', | ||
}).build(); | ||
request.client_assertion_type = 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer'; | ||
request.client_assertion = pop.jwt; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export * from './AuthorizationUtil'; | ||
export * from './notifications'; | ||
export * from './OpenIDUtils'; | ||
export * from './AccessTokenUtil'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters