Skip to content

Commit

Permalink
Merge pull request #1724 from skynet2/vp-add-extra-claims
Browse files Browse the repository at this point in the history
feat: add extra claims in vp
  • Loading branch information
fqutishat authored May 21, 2024
2 parents 4e496dc + 46ba103 commit 9a36f72
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pkg/service/oidc4vp/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ type CredentialMetadata struct {
IssuanceDate *util.TimeWrapper `json:"issuanceDate,omitempty"`
ExpirationDate *util.TimeWrapper `json:"expirationDate,omitempty"`
CustomClaims map[string]Claims `json:"customClaims,omitempty"`

Name interface{} `json:"name,omitempty"`
AwardedDate interface{} `json:"awardedDate,omitempty"`
Description interface{} `json:"description,omitempty"`
}

type ServiceInterface interface {
Expand Down
10 changes: 10 additions & 0 deletions pkg/service/oidc4vp/oidc4vp_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ const (
customScopeProperty = "_scope"
)

const (
additionalClaimFieldName = "name"
additionalClaimFieldDesc = "description"
additionalClaimFieldAwardedDate = "awardedDate"
)

var ErrDataNotFound = errors.New("data not found")

type eventService interface {
Expand Down Expand Up @@ -601,6 +607,10 @@ func (s *Service) RetrieveClaims(
ExpirationDate: credContents.Expired,
}

credMeta.Name = cred.CustomField(additionalClaimFieldName)
credMeta.Description = cred.CustomField(additionalClaimFieldDesc)
credMeta.AwardedDate = cred.CustomField(additionalClaimFieldAwardedDate)

if credContents.Issuer != nil {
credMeta.Issuer = verifiable.IssuerToJSON(*credContents.Issuer)
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/service/oidc4vp/oidc4vp_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,11 @@ func TestService_RetrieveClaims(t *testing.T) {
require.NotEmpty(t, claims["http://example.gov/credentials/3732"].Issuer)
require.NotEmpty(t, claims["http://example.gov/credentials/3732"].IssuanceDate)
require.Empty(t, claims["http://example.gov/credentials/3732"].ExpirationDate)

require.Equal(t, "abcd", claims["http://example.gov/credentials/3732"].Name)
require.Equal(t, "some-description", claims["http://example.gov/credentials/3732"].Description)
require.Nil(t, claims["http://example.gov/credentials/3732"].AwardedDate)

require.Equal(t,
oidc4vp.CredentialMetadata{CustomClaims: map[string]oidc4vp.Claims{customScope: {"key1": "value1"}}},
claims["_scope"],
Expand Down
2 changes: 1 addition & 1 deletion pkg/service/oidc4vp/testdata/university_degree.jwt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJpYXQiOjE1ODQzOTgyNDYsImlzcyI6ImRpZDp0cnVzdGJsb2NrOmFiYyIsImp0aSI6Imh0dHA6Ly9leGFtcGxlLmdvdi9jcmVkZW50aWFscy8zNzMyIiwibmJmIjoxNTg0Mzk4MjQ2LCJzdWIiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vdzNjLWNjZy5naXRodWIuaW8vbGRzLWp3czIwMjAvY29udGV4dHMvbGRzLWp3czIwMjAtdjEuanNvbiIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIiwiaHR0cHM6Ly93M2lkLm9yZy92Yy9zdGF0dXMtbGlzdC8yMDIxL3YxIl0sImNyZWRlbnRpYWxTdGF0dXMiOnsiaWQiOiJodHRwczovL2lzc3Vlci12Y3Muc2FuZGJveC50cnVzdGJsb2MuZGV2L3ZjLWlzc3Vlci10ZXN0LTIvc3RhdHVzLzEjMCIsInN0YXR1c0xpc3RDcmVkZW50aWFsIjoiIiwic3RhdHVzTGlzdEluZGV4IjoiMSIsInN0YXR1c1B1cnBvc2UiOiIyIiwidHlwZSI6IlN0YXR1c0xpc3QyMDIxRW50cnkifSwi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