Skip to content

Commit

Permalink
feat: multi issuance with same type
Browse files Browse the repository at this point in the history
Signed-off-by: Mykhailo Sizov <[email protected]>
  • Loading branch information
mishasizov-SK committed Mar 19, 2024
1 parent b96e240 commit 33a4380
Show file tree
Hide file tree
Showing 19 changed files with 1,962 additions and 1,371 deletions.
1 change: 0 additions & 1 deletion pkg/kms/mocks/kms_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions pkg/observability/tracing/wrappers/oidc4ci/oidc4ci_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ func (w *Wrapper) InitiateIssuance(
span.SetAttributes(attribute.String("profile_id", profile.ID))
span.SetAttributes(attributeutil.JSON("initiate_issuance_request", req, attributeutil.WithRedacted("ClaimData")))

if len(req.ClaimData) > 0 { //nolint:staticcheck
span.SetAttributes(attribute.StringSlice("claim_keys", lo.Keys(req.ClaimData))) //nolint:staticcheck
for _, credConfig := range req.CredentialConfiguration {
if len(credConfig.ClaimData) > 0 { //nolint:staticcheck
span.SetAttributes(attribute.StringSlice("claim_keys", lo.Keys(credConfig.ClaimData))) //nolint:staticcheck
}
}

resp, err := w.svc.InitiateIssuance(ctx, req, profile)
Expand Down
12 changes: 10 additions & 2 deletions pkg/observability/tracing/wrappers/oidc4ci/oidc4ci_wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,22 @@ func TestWrapper_InitiateIssuance(t *testing.T) {
svc := NewMockService(ctrl)
svc.EXPECT().InitiateIssuance(gomock.Any(),
&oidc4ci.InitiateIssuanceRequest{
ClaimData: map[string]interface{}{"foo": "bar"},
CredentialConfiguration: []oidc4ci.InitiateIssuanceCredentialConfiguration{
{
ClaimData: map[string]interface{}{"foo": "bar"},
},
},
},
&profile.Issuer{}).Return(&oidc4ci.InitiateIssuanceResponse{}, nil).Times(1)

w := Wrap(svc, trace.NewNoopTracerProvider().Tracer(""))

_, err := w.InitiateIssuance(context.Background(), &oidc4ci.InitiateIssuanceRequest{
ClaimData: map[string]interface{}{"foo": "bar"},
CredentialConfiguration: []oidc4ci.InitiateIssuanceCredentialConfiguration{
{
ClaimData: map[string]interface{}{"foo": "bar"},
},
},
}, &profile.Issuer{})
require.NoError(t, err)
}
Expand Down
22 changes: 13 additions & 9 deletions pkg/restapi/v1/issuer/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,23 +435,29 @@ func (c *Controller) initiateIssuance(
profile *profileapi.Issuer,
) (*InitiateOIDC4CIResponse, string, error) {
issuanceReq := &oidc4ci.InitiateIssuanceRequest{
CredentialTemplateID: lo.FromPtr(req.CredentialTemplateId),
ClientInitiateIssuanceURL: lo.FromPtr(req.ClientInitiateIssuanceUrl),
ClientWellKnownURL: lo.FromPtr(req.ClientWellknown),
ClaimEndpoint: lo.FromPtr(req.ClaimEndpoint),
GrantType: string(lo.FromPtr(req.GrantType)),
ResponseType: lo.FromPtr(req.ResponseType),
Scope: lo.FromPtr(req.Scope),
OpState: lo.FromPtr(req.OpState),
ClaimData: lo.FromPtr(req.ClaimData),
UserPinRequired: lo.FromPtr(req.UserPinRequired),
CredentialExpiresAt: req.CredentialExpiresAt,
CredentialName: lo.FromPtr(req.CredentialName),
CredentialDescription: lo.FromPtr(req.CredentialDescription),
WalletInitiatedIssuance: lo.FromPtr(req.WalletInitiatedIssuance),
CredentialConfiguration: []oidc4ci.InitiateIssuanceCredentialConfiguration{},
}

if req.CredentialTemplateId != nil && lo.FromPtr(req.CredentialTemplateId) != "" {
issuanceReq.CredentialConfiguration = append(issuanceReq.CredentialConfiguration,
oidc4ci.InitiateIssuanceCredentialConfiguration{
ClaimData: lo.FromPtr(req.ClaimData),
ClaimEndpoint: lo.FromPtr(req.ClaimEndpoint),
CredentialTemplateID: lo.FromPtr(req.CredentialTemplateId),
CredentialExpiresAt: req.CredentialExpiresAt,
CredentialName: lo.FromPtr(req.CredentialName),
CredentialDescription: lo.FromPtr(req.CredentialDescription),
})
}

if req.CredentialConfiguration != nil && len(*req.CredentialConfiguration) > 0 {
for _, multiCredentialIssuance := range lo.FromPtr(req.CredentialConfiguration) {
credConfig := oidc4ci.InitiateIssuanceCredentialConfiguration{
Expand All @@ -471,9 +477,7 @@ func (c *Controller) initiateIssuance(
}
}

issuanceReq.CredentialConfiguration = append(issuanceReq.CredentialConfiguration,
credConfig,
)
issuanceReq.CredentialConfiguration = append(issuanceReq.CredentialConfiguration, credConfig)
}
}

Expand Down
30 changes: 17 additions & 13 deletions pkg/restapi/v1/issuer/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,23 +791,26 @@ func TestController_InitiateCredentialIssuance(t *testing.T) {

t.Run("Success", func(t *testing.T) {
expectedInitiateIssuanceReq := &oidc4ci.InitiateIssuanceRequest{
CredentialTemplateID: "templateID",
ClientInitiateIssuanceURL: "https://wallet.example.com/initiate_issuance",
ClientWellKnownURL: "https://wallet.example.com/.well-known/openid-configuration",
ClaimEndpoint: "https://vcs.pb.example.com/claim",
GrantType: "authorization_code",
ResponseType: "token",
Scope: []string{"openid"},
OpState: "eyJhbGciOiJSU0Et",
ClaimData: map[string]interface{}{
"key": "value",
},
UserPinRequired: true,
CredentialExpiresAt: now,
CredentialName: "name1",
CredentialDescription: "description1",
WalletInitiatedIssuance: true,
UserPinRequired: true,
WalletInitiatedIssuance: true,
CredentialConfiguration: []oidc4ci.InitiateIssuanceCredentialConfiguration{
{
ClaimData: map[string]interface{}{
"key": "value",
},
ClaimEndpoint: "https://vcs.pb.example.com/claim",
CredentialTemplateID: "templateID",
CredentialExpiresAt: now,
CredentialName: "name1",
CredentialDescription: "description1",
ComposeCredential: nil,
},
{
ClaimData: map[string]interface{}{
"key2": "value2",
Expand Down Expand Up @@ -1555,9 +1558,10 @@ func TestController_ValidatePreAuthorizedCodeRequest(t *testing.T) {
TransactionData: oidc4ci.TransactionData{
OpState: "random_op_state",
Scope: []string{"a", "b"},
CredentialConfiguration: map[string]*oidc4ci.TxCredentialConfiguration{
"CredentialConfigurationID": {
AuthorizationDetails: getTestAuthorizationDetails(t, true),
CredentialConfiguration: []*oidc4ci.TxCredentialConfiguration{
{
AuthorizationDetails: getTestAuthorizationDetails(t, true),
CredentialConfigurationID: "CredentialConfigurationID",
},
},
},
Expand Down
46 changes: 18 additions & 28 deletions pkg/service/oidc4ci/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,21 @@ type TransactionData struct {
UserPin string
DID string
WalletInitiatedIssuance bool
CredentialConfiguration map[string]*TxCredentialConfiguration
CredentialConfiguration []*TxCredentialConfiguration
}

type TxCredentialConfiguration struct {
CredentialTemplate *profileapi.CredentialTemplate
OIDCCredentialFormat vcsverifiable.OIDCFormat
ClaimEndpoint string
ClaimDataID string
ClaimDataType ClaimDataType
CredentialName string
CredentialDescription string
CredentialExpiresAt *time.Time
PreAuthCodeExpiresAt *time.Time
ID string
CredentialTemplate *profileapi.CredentialTemplate
OIDCCredentialFormat vcsverifiable.OIDCFormat
ClaimEndpoint string
ClaimDataID string
ClaimDataType ClaimDataType
CredentialName string
CredentialDescription string
CredentialExpiresAt *time.Time
PreAuthCodeExpiresAt *time.Time
CredentialConfigurationID string
// AuthorizationDetails may be defined on Authorization Request via using "authorization_details" parameter.
// If "scope" param is used, this field will stay empty.
AuthorizationDetails *AuthorizationDetails
Expand Down Expand Up @@ -169,26 +171,14 @@ type IssuerIDPOIDCConfiguration struct {

// InitiateIssuanceRequest is the request used by the Issuer to initiate the OIDC VC issuance interaction.
type InitiateIssuanceRequest struct {
// Deprecated: Use CredentialConfiguration instead.
CredentialTemplateID string
ClientInitiateIssuanceURL string
ClientWellKnownURL string
// Deprecated: Use CredentialConfiguration instead.
ClaimEndpoint string
GrantType string
ResponseType string
Scope []string
OpState string
// Deprecated: Use CredentialConfiguration instead.
ClaimData map[string]interface{}
UserPinRequired bool
// Deprecated: Use CredentialConfiguration instead.
CredentialExpiresAt *time.Time
// Deprecated: Use CredentialConfiguration instead.
CredentialName string
// Deprecated: Use CredentialConfiguration instead.
CredentialDescription string
WalletInitiatedIssuance bool
GrantType string
ResponseType string
Scope []string
OpState string
UserPinRequired bool
WalletInitiatedIssuance bool
// CredentialConfiguration aimed to initialise multi credential issuance.
CredentialConfiguration []InitiateIssuanceCredentialConfiguration
}
Expand Down
Loading

0 comments on commit 33a4380

Please sign in to comment.