Skip to content

Commit a691eb8

Browse files
authored
Merge pull request #72 from Sphereon-Opensource/develop
New release
2 parents c412093 + 861ee87 commit a691eb8

27 files changed

Lines changed: 146 additions & 235 deletions

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
[![CI](https://github.com/Sphereon-Opensource/OID4VCI/actions/workflows/build-test-on-pr.yml/badge.svg)](https://github.com/Sphereon-Opensource/OID4VCI/actions/workflows/build-test-on-pr.yml) [![codecov](https://codecov.io/gh/Sphereon-Opensource/OID4VCI/branch/develop/graph/badge.svg)](https://codecov.io/gh/Sphereon-Opensource/OID4VCI) [![NPM Version](https://img.shields.io/npm/v/@sphereon/oid4vci-client.svg)](https://npm.im/@sphereon/oid4vci-client)
99

10-
_IMPORTANT the packages are in an early development stage and currently only supports the pre-authorized code flow of
11-
OpenID4VCI! Work is underway for the Authorized Flows as well, but not fully supported yet_
10+
_IMPORTANT the packages are still in an early development stage, as such breaking changes are to be expected_
1211

1312
# Background
1413

@@ -44,7 +43,7 @@ The spec lists 2 flows:
4443

4544
## Authorized Code Flow
4645

47-
This flow isn't fully supported yet, so you might run into issues trying to use it.
46+
This flow is supported but might need more work, so you might run into issues trying to use it.
4847

4948
## Pre-authorized Code Flow
5049

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"packages": [
33
"packages/*"
44
],
5-
"version": "0.7.3",
5+
"version": "0.8.0",
66
"npmClient": "pnpm",
77
"command": {
88
"publish": {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"fix:lint": "eslint . --fix --ext .ts",
1212
"fix:prettier": "prettier --write \"{packages,__tests__,!dist}/**/*.{ts,tsx,js,json,md,yml}\"",
1313
"build": "pnpm -r --stream build",
14+
"build:clean": "lerna clean -y && pnpm install && lerna run build:clean --concurrency 1",
1415
"test:ci": "jest --config=jest.json",
1516
"test": "jest --verbose --config=jest.json --coverage=true --detectOpenHandles",
1617
"clean": "rimraf --glob **/dist **/coverage **/pnpm-lock.yaml packages/**/node_modules node_modules packages/**/tsconfig.tsbuildinfo",

packages/callback-example/CHANGELOG.md

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,15 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
77

88
**Note:** Version bump only for package @sphereon/oid4vci-callback-example
99

10-
11-
12-
13-
1410
## [0.7.2](https://github.com/Sphereon-Opensource/OID4VCI/compare/v0.7.1...v0.7.2) (2023-09-28)
1511

1612
**Note:** Version bump only for package @sphereon/oid4vci-callback-example
1713

18-
19-
20-
21-
2214
## [0.7.1](https://github.com/Sphereon-Opensource/OID4VCI/compare/v0.7.0...v0.7.1) (2023-09-28)
2315

24-
2516
### Bug Fixes
2617

27-
* Better match credential offer types and formats onto issuer metadata ([4044c21](https://github.com/Sphereon-Opensource/OID4VCI/commit/4044c2175b4cbee16f44c8bb5499bba249ca4993))
28-
29-
30-
31-
18+
- Better match credential offer types and formats onto issuer metadata ([4044c21](https://github.com/Sphereon-Opensource/OID4VCI/commit/4044c2175b4cbee16f44c8bb5499bba249ca4993))
3219

3320
# [0.7.0](https://github.com/Sphereon-Opensource/OID4VCI/compare/v0.6.0...v0.7.0) (2023-08-19)
3421

packages/callback-example/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"main": "dist/index.js",
77
"types": "dist/index.d.ts",
88
"scripts": {
9-
"build": "tsc"
9+
"build": "tsc",
10+
"build:clean": "tsc --build --clean && tsc --build"
1011
},
1112
"dependencies": {
1213
"@digitalcredentials/did-method-key": "^2.0.3",

packages/client/CHANGELOG.md

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,20 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
77

88
**Note:** Version bump only for package @sphereon/oid4vci-client
99

10-
11-
12-
13-
1410
## [0.7.2](https://github.com/Sphereon-Opensource/OID4VCI/compare/v0.7.1...v0.7.2) (2023-09-28)
1511

16-
1712
### Bug Fixes
1813

19-
* id lookup against server metadata not working ([592ec4b](https://github.com/Sphereon-Opensource/OID4VCI/commit/592ec4b837898eb3022d19479d79b6065e7a0d9e))
20-
21-
22-
23-
14+
- id lookup against server metadata not working ([592ec4b](https://github.com/Sphereon-Opensource/OID4VCI/commit/592ec4b837898eb3022d19479d79b6065e7a0d9e))
2415

2516
## [0.7.1](https://github.com/Sphereon-Opensource/OID4VCI/compare/v0.7.0...v0.7.1) (2023-09-28)
2617

27-
2818
### Bug Fixes
2919

30-
* Better match credential offer types and formats onto issuer metadata ([4044c21](https://github.com/Sphereon-Opensource/OID4VCI/commit/4044c2175b4cbee16f44c8bb5499bba249ca4993))
31-
* clearinterval ([214e3c6](https://github.com/Sphereon-Opensource/OID4VCI/commit/214e3c6d7ced9b27c50186db8ed876330230a6a5))
32-
* relax auth_endpoint handling. Doesn't have to be available when doing pre-auth flow. Client handles errors anyway in case of auth/par flow ([ce39958](https://github.com/Sphereon-Opensource/OID4VCI/commit/ce39958f21f82243f26111fd14bd2443517eef9c))
33-
* relax auth_endpoint handling. Doesn't have to be available when doing pre-auth flow. Client handles errors anyway in case of auth/par flow ([cb5f9c1](https://github.com/Sphereon-Opensource/OID4VCI/commit/cb5f9c1c12285508c6d403814d032e8883a59e7d))
34-
35-
36-
37-
20+
- Better match credential offer types and formats onto issuer metadata ([4044c21](https://github.com/Sphereon-Opensource/OID4VCI/commit/4044c2175b4cbee16f44c8bb5499bba249ca4993))
21+
- clearinterval ([214e3c6](https://github.com/Sphereon-Opensource/OID4VCI/commit/214e3c6d7ced9b27c50186db8ed876330230a6a5))
22+
- relax auth_endpoint handling. Doesn't have to be available when doing pre-auth flow. Client handles errors anyway in case of auth/par flow ([ce39958](https://github.com/Sphereon-Opensource/OID4VCI/commit/ce39958f21f82243f26111fd14bd2443517eef9c))
23+
- relax auth_endpoint handling. Doesn't have to be available when doing pre-auth flow. Client handles errors anyway in case of auth/par flow ([cb5f9c1](https://github.com/Sphereon-Opensource/OID4VCI/commit/cb5f9c1c12285508c6d403814d032e8883a59e7d))
3824

3925
# [0.7.0](https://github.com/Sphereon-Opensource/OID4VCI/compare/v0.6.0...v0.7.0) (2023-08-19)
4026

packages/client/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ import { OpenID4VCIClient } from '@sphereon/oid4vci-client';
5757
// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.
5858
const client = await OpenID4VCIClient.fromURI({
5959
uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',
60-
flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW, // The flow to use
6160
kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID. You can defer this also to when the acquireCredential method is called
6261
alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called
6362
clientId: 'test-clientId', // The clientId if the Authrozation Service requires it. If a clientId is needed you can defer this also to when the acquireAccessToken method is called

packages/client/lib/AccessTokenClient.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import {
44
AccessTokenResponse,
55
assertedUniformCredentialOffer,
66
AuthorizationServerOpts,
7+
AuthzFlowType,
78
EndpointMetadata,
89
getIssuerFromCredentialOfferPayload,
910
GrantTypes,
10-
isPreAuthCode,
1111
IssuerOpts,
1212
OpenIDResponse,
1313
PRE_AUTH_CODE_LITERAL,
@@ -67,6 +67,7 @@ export class AccessTokenClient {
6767
issuerOpts?: IssuerOpts;
6868
}): Promise<OpenIDResponse<AccessTokenResponse>> {
6969
this.validate(accessTokenRequest, isPinRequired);
70+
7071
const requestTokenURL = AccessTokenClient.determineTokenURL({
7172
asOpts,
7273
issuerOpts,
@@ -76,45 +77,44 @@ export class AccessTokenClient {
7677
? await MetadataClient.retrieveAllMetadata(issuerOpts.issuer, { errorOnNotFound: false })
7778
: undefined,
7879
});
80+
7981
return this.sendAuthCode(requestTokenURL, accessTokenRequest);
8082
}
8183

8284
public async createAccessTokenRequest(opts: AccessTokenRequestOpts): Promise<AccessTokenRequest> {
8385
const { asOpts, pin, codeVerifier, code, redirectUri } = opts;
8486
const credentialOfferRequest = await toUniformCredentialOfferRequest(opts.credentialOffer);
8587
const request: Partial<AccessTokenRequest> = {};
88+
8689
if (asOpts?.clientId) {
8790
request.client_id = asOpts.clientId;
8891
}
8992

90-
this.assertNumericPin(this.isPinRequiredValue(credentialOfferRequest.credential_offer), pin);
91-
request.user_pin = pin;
93+
if (credentialOfferRequest.supportedFlows.includes(AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW)) {
94+
this.assertNumericPin(this.isPinRequiredValue(credentialOfferRequest.credential_offer), pin);
95+
request.user_pin = pin;
9296

93-
const isPreAuth = isPreAuthCode(credentialOfferRequest);
94-
if (isPreAuth) {
95-
if (codeVerifier) {
96-
throw new Error('Cannot pass a code_verifier when flow type is pre-authorized');
97-
}
9897
request.grant_type = GrantTypes.PRE_AUTHORIZED_CODE;
9998
// we actually know it is there because of the isPreAuthCode call
10099
request[PRE_AUTH_CODE_LITERAL] =
101100
credentialOfferRequest?.credential_offer.grants?.['urn:ietf:params:oauth:grant-type:pre-authorized_code']?.[PRE_AUTH_CODE_LITERAL];
101+
102+
return request as AccessTokenRequest;
102103
}
103-
if (!isPreAuth && credentialOfferRequest.credential_offer.grants?.authorization_code?.issuer_state) {
104-
this.throwNotSupportedFlow(); // not supported yet
104+
105+
if (credentialOfferRequest.supportedFlows.includes(AuthzFlowType.AUTHORIZATION_CODE_FLOW)) {
105106
request.grant_type = GrantTypes.AUTHORIZATION_CODE;
106-
}
107-
if (codeVerifier) {
108-
request.code_verifier = codeVerifier;
109107
request.code = code;
110108
request.redirect_uri = redirectUri;
111-
request.grant_type = GrantTypes.AUTHORIZATION_CODE;
112-
}
113-
if (request.grant_type === GrantTypes.AUTHORIZATION_CODE && isPreAuth) {
114-
throw Error('A pre_authorized_code flow cannot have an issuer state in the credential offer');
109+
110+
if (codeVerifier) {
111+
request.code_verifier = codeVerifier;
112+
}
113+
114+
return request as AccessTokenRequest;
115115
}
116116

117-
return request as AccessTokenRequest;
117+
throw new Error('Credential offer request does not follow neither pre-authorized code nor authorization code flow requirements.');
118118
}
119119

120120
private assertPreAuthorizedGrantType(grantType: GrantTypes): void {

0 commit comments

Comments
 (0)