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

Merged
merged 36 commits into from
Nov 19, 2024
Merged

feat!: auth code flow #2088

merged 36 commits into from
Nov 19, 2024

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: fd0c71f

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 !!

.babelrc Outdated Show resolved Hide resolved
demo-openid/README.md Outdated Show resolved Hide resolved
@@ -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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah yeah, provider needs esm support which does not work with ts-node. I'll update them all to tsx

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh wait the issue is:

  • tsx supports esm but no decorators (so works for provider)
  • ts-node does nont support esm, but does support decorators (so works for issuer/holder/verifier)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

did my best but no luck. We will either have to update to the new decorator support (still to experimental i think), or move away from decorators.

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(),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bit unfortunate but both don't give the same result.

First one make it an enum value, which makes typescript more strict. In this case I need it as string.

Second one doesn't give type infer, but just casts it to string instead of a constant.

demo-openid/src/Holder.ts Show resolved Hide resolved
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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The object will never be defined it it's not true. So i think true is more clear here. Alternative is empty object to indicate it's required but that felt not explicit.

Or another top-level prop for presentationRequired and then presentation for the details, but then you can still have that presentation is undefined (in TS) even if required is true. So no if you check for required == true, the other props will also be defined

Signed-off-by: Timo Glastra <[email protected]>
Signed-off-by: Timo Glastra <[email protected]>
…instead of `vp_formats supported` (#2089)

Signed-off-by: Timo Glastra <[email protected]>
Signed-off-by: Timo Glastra <[email protected]>
Signed-off-by: Timo Glastra <[email protected]>
@TimoGlastra TimoGlastra changed the title feat! auth code flow feat!: auth code flow Nov 16, 2024
Signed-off-by: Timo Glastra <[email protected]>
Signed-off-by: Timo Glastra <[email protected]>
Signed-off-by: Timo Glastra <[email protected]>
Signed-off-by: Timo Glastra <[email protected]>
Signed-off-by: Timo Glastra <[email protected]>
Signed-off-by: Timo Glastra <[email protected]>
Signed-off-by: Timo Glastra <[email protected]>
@TimoGlastra TimoGlastra merged commit 17ec6b8 into main Nov 19, 2024
10 of 14 checks passed
@TimoGlastra TimoGlastra deleted the auth-code-flow-2 branch November 19, 2024 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants