Skip to content
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

feat! auth code flow #2088

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open

feat! auth code flow #2088

wants to merge 17 commits into from

Conversation

TimoGlastra
Copy link
Contributor

See #2056

auer-martin and others added 17 commits August 30, 2024 11:04
Signed-off-by: Timo Glastra <[email protected]>
Signed-off-by: Timo Glastra <[email protected]>
Signed-off-by: Timo Glastra <[email protected]>
…esentation during issuance and batch issuance.

This is a big change to OpenID4VCI in Credo, with the neccsary breaking changes since we first added it to the framework. Over time the spec has changed significantly, but also our understanding of the standards and protocols.

**Authorization Code Flow**
Credo now supports the authorization code flow, for both issuer and holder. An issuer can configure multiple authorization servers, and work with external authorization servers as well. The integration is based on OAuth2, with several extension specifications, mainly the OAuth2 JWT Access Token Profile, as well as Token Introspection (for opaque access tokens). Verification works out of the box, as longs as the authorization server has a `jwks_uri` configured. For Token Introspection it's also required to provide a `clientId` and `clientSecret` in the authorization server config.

To use an external authorization server, the authorization server MUST include the `issuer_state` parameter from the credential offer in the access token. Otherwise it's not possible for Credo to correlate the authorization session to the offer session.

The demo-openid contains an example with external authorization server, which can be used as reference. The Credo authorization server supports DPoP and PKCE.

**Batch Issuance**
The credential request to credential mapper has been updated to support multiple proofs, and also multiple credential instances. The client can now also handle batch issuance.

**Presentation During Issuance**
The presenation during issuance allows to request presentation using OID4VP before granting authorization for issuance of one or more credentials. This flow is automatically handled by the `resolveAuthorizationRequest` method on the oid4vci holder service.

Signed-off-by: Timo Glastra <[email protected]>
Copy link

changeset-bot bot commented Nov 9, 2024

🦋 Changeset detected

Latest commit: 35c2c96

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 14 packages
Name Type
@credo-ts/openid4vc Minor
@credo-ts/action-menu Minor
@credo-ts/anoncreds Minor
@credo-ts/askar Minor
@credo-ts/bbs-signatures Minor
@credo-ts/cheqd Minor
@credo-ts/core Minor
@credo-ts/drpc Minor
@credo-ts/indy-sdk-to-askar-migration Minor
@credo-ts/indy-vdr Minor
@credo-ts/node Minor
@credo-ts/question-answer Minor
@credo-ts/react-native Minor
@credo-ts/tenants Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

@berendsliedrecht berendsliedrecht left a comment

Choose a reason for hiding this comment

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

There are quite some TODO's still, but I assume everything that should be fixed before merging will be fixed :). Good addition @TimoGlastra !!

@@ -0,0 +1,11 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

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

we use babel now?

Comment on lines +9 to +10
- ✅ Issuing a credential without authorization (pre authorized).
- ✅ Issuing a credenital with external authorization server
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- ✅ Issuing a credential without authorization (pre authorized).
- ✅ Issuing a credenital with external authorization server
- ✅ Issuing a credential without authorization (pre authorized code flow).
- ✅ Issuing a credenital with external authorization server (authorized code flow).

@@ -10,15 +10,19 @@
"license": "Apache-2.0",
"scripts": {
"issuer": "ts-node src/IssuerInquirer.ts",
"provider": "tsx src/Provider.ts",
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can just use ts-node or tsx for all of them, we don't need both

if (resolvedAuthorizationRequest.authorizationFlow === OpenId4VciAuthorizationFlow.PresentationDuringIssuance) {
return {
...resolvedAuthorizationRequest,
authorizationFlow: `${OpenId4VciAuthorizationFlow.PresentationDuringIssuance}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
authorizationFlow: `${OpenId4VciAuthorizationFlow.PresentationDuringIssuance}`,
authorizationFlow: OpenId4VciAuthorizationFlow.PresentationDuringIssuance,

or

Suggested change
authorizationFlow: `${OpenId4VciAuthorizationFlow.PresentationDuringIssuance}`,
authorizationFlow: OpenId4VciAuthorizationFlow.PresentationDuringIssuance.toString(),

} else {
return {
...resolvedAuthorizationRequest,
authorizationFlow: `${OpenId4VciAuthorizationFlow.Oauth2Redirect}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here.

@@ -39,6 +42,8 @@ export const matrrLaunchpadDraft11JwtVcJson = {
{
id: 'b4c4cdf5-ccc9-4945-8c19-9334558653b2',
format: 'ldp_vc',
// FIXME: should we make this optional? Seems a lot of types break on this
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// FIXME: should we make this optional? Seems a lot of types break on this
// TODO: should we make this optional? Seems a lot of types break on this

Do we differentiate between FIXME and TODO? We should keep it conistent if they mean the same.

Might also be nice to have something like // TODO(oid): bla bla

next()
})

// This one will be called for all errors that are thrown
// eslint-disable-next-line @typescript-eslint/no-explicit-any
contextRouter.use(async (_error: unknown, req: OpenId4VcIssuanceRequest, _res: unknown, next: any) => {
contextRouter.use(async (_error: unknown, req: OpenId4VcIssuanceRequest, res: Response, next: any) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

next is NextFunction if I am not mistaken

OpenId4VciSignSdJwtCredential,
OpenId4VciSignW3cCredential,
OpenId4VciSignMdocCredential,
OpenId4VciSignW3cCredentials,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as with the holder service file. Would really benefit from a split up in files and some helper functions to make it a lot easier to read.

/**
* Whether presentation during issuance is required.
*/
required: true
Copy link
Contributor

Choose a reason for hiding this comment

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

should this not be a boolean?

url: fullRequestUrl,
} as const

// What error does this throw?
Copy link
Contributor

Choose a reason for hiding this comment

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

does this need a TODO?

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