Skip to content

Commit a9cd134

Browse files
authored
Merge pull request #71 from Sphereon-Opensource/feature/enable-authorization-code-flow-helpers
Feature/enable authorization code flow helpers
2 parents 2d2c2f2 + 1114e83 commit a9cd134

20 files changed

Lines changed: 130 additions & 231 deletions

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/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)