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: return issuer uri in credential refresh response #1768

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
405 changes: 203 additions & 202 deletions api/spec/openapi.gen.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1659,10 +1659,13 @@ components:
type: string
anyOf:
- { }
issuerURI:
type: string
x-tags:
- refresh
required:
- verifiable_credential
- issuerURI
DeprecatedComposeOIDC4CICredential:
title: DeprecatedComposeOIDC4CICredential
type: object
Expand Down
3 changes: 2 additions & 1 deletion pkg/restapi/v1/refresh/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ func (c *Controller) GetRefreshedCredential(
}

return ctx.JSON(http.StatusOK, GetRefreshedCredentialResp{
VerifiableCredential: resp,
VerifiableCredential: resp.Credential,
IssuerURI: resp.IssuerURL,
})
}

Expand Down
5 changes: 4 additions & 1 deletion pkg/restapi/v1/refresh/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,10 @@ func TestGetRefreshedCredential(t *testing.T) {
Return(issuer, nil)

refreshSvc.EXPECT().GetRefreshedCredential(gomock.Any(), gomock.Any(), *issuer).
Return(signedRequestedCredentialsVP.Presentation.Credentials()[0], nil)
Return(&refresh2.GetRefreshedCredentialResponse{
Credential: signedRequestedCredentialsVP.Presentation.Credentials()[0],
IssuerURL: "https://issuer.example.com/oidc/idp/profile-id/v1.0",
}, nil)

ctr := refresh.NewController(&refresh.Config{
ProfileService: profileSvc,
Expand Down
2 changes: 1 addition & 1 deletion pkg/restapi/v1/refresh/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type CredentialRefreshService interface {
ctx context.Context,
presentation *verifiable.Presentation,
issuer profileapi.Issuer,
) (*verifiable.Credential, error)
) (*refresh.GetRefreshedCredentialResponse, error)
}

type ProofChecker interface {
Expand Down
1 change: 1 addition & 0 deletions pkg/restapi/v1/refresh/openapi.gen.go

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

17 changes: 13 additions & 4 deletions pkg/service/refresh/refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"encoding/json"
"errors"
"fmt"
"net/url"
"time"

"github.com/davecgh/go-spew/spew"
Expand Down Expand Up @@ -110,7 +111,7 @@ func (s *Service) GetRefreshedCredential(
ctx context.Context,
presentation *verifiable.Presentation,
issuer profile.Issuer,
) (*verifiable.Credential, error) {
) (*GetRefreshedCredentialResponse, error) {
resultEvent := &Event{
WebHook: issuer.WebHook,
ProfileID: issuer.ID,
Expand Down Expand Up @@ -238,11 +239,19 @@ func (s *Service) GetRefreshedCredential(

if err != nil {
s.tryPublish(ctx, spi.CredentialRefreshFailed, resultEvent, string(tx.ID), err)
} else {
s.tryPublish(ctx, spi.CredentialRefreshSuccessful, resultEvent, string(tx.ID), nil)
return nil, err
}

issuerURL, _ := url.JoinPath(s.cfg.VcsAPIURL, "oidc/idp", tx.ProfileID, tx.ProfileVersion)

credentialResponse := &GetRefreshedCredentialResponse{
Credential: updatedCred,
IssuerURL: issuerURL,
}

return updatedCred, err
s.tryPublish(ctx, spi.CredentialRefreshSuccessful, resultEvent, string(tx.ID), nil)

return credentialResponse, nil
}

func (s *Service) findCredentialTemplate(
Expand Down
21 changes: 14 additions & 7 deletions pkg/service/refresh/refresh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ func TestGetRefreshedCredential(t *testing.T) {
Return(errors.New("ignored"))

srv := refresh.NewRefreshService(&refresh.Config{
VcsAPIURL: "https://issuer.example.com/",
PresentationVerifier: verifier,
TxStore: txStore,
ClaimsStore: claimStore,
Expand Down Expand Up @@ -224,7 +225,9 @@ func TestGetRefreshedCredential(t *testing.T) {
Return(&issuecredential.Transaction{
ID: "some-id",
TransactionData: issuecredential.TransactionData{
DID: "some-did",
DID: "some-did",
ProfileID: "profile-id",
ProfileVersion: "v1.0",
CredentialConfiguration: []*issuecredential.TxCredentialConfiguration{
{
ClaimDataID: "some-claim-id",
Expand Down Expand Up @@ -268,9 +271,11 @@ func TestGetRefreshedCredential(t *testing.T) {
return nil, nil, nil
})

cred, err := srv.GetRefreshedCredential(context.TODO(), signedRequestedCredentialsVP.Presentation, targetIssuer)
credentialResponse, err := srv.GetRefreshedCredential(context.TODO(), signedRequestedCredentialsVP.Presentation,
targetIssuer)
assert.NoError(t, err)
assert.Equal(t, cred, targetCred)
assert.Equal(t, credentialResponse.Credential, targetCred)
assert.Equal(t, credentialResponse.IssuerURL, "https://issuer.example.com/oidc/idp/profile-id/v1.0")
})

t.Run("issue err", func(t *testing.T) {
Expand Down Expand Up @@ -378,9 +383,10 @@ func TestGetRefreshedCredential(t *testing.T) {
return nil, nil, nil
})

cred, err := srv.GetRefreshedCredential(context.TODO(), signedRequestedCredentialsVP.Presentation, targetIssuer)
credentialResponse, err := srv.GetRefreshedCredential(context.TODO(), signedRequestedCredentialsVP.Presentation,
targetIssuer)
assert.ErrorContains(t, err, "failed to issue credential")
assert.Nil(t, cred)
assert.Nil(t, credentialResponse)
})

t.Run("prepare err", func(t *testing.T) {
Expand Down Expand Up @@ -475,8 +481,9 @@ func TestGetRefreshedCredential(t *testing.T) {
return nil, nil, nil
})

cred, err := srv.GetRefreshedCredential(context.TODO(), signedRequestedCredentialsVP.Presentation, targetIssuer)
credentialResponse, err := srv.GetRefreshedCredential(context.TODO(), signedRequestedCredentialsVP.Presentation,
targetIssuer)
assert.ErrorContains(t, err, "failed to prepare credential")
assert.Nil(t, cred)
assert.Nil(t, credentialResponse)
})
}
6 changes: 6 additions & 0 deletions pkg/service/refresh/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package refresh

import (
"github.com/trustbloc/vc-go/presexch"
"github.com/trustbloc/vc-go/verifiable"

"github.com/trustbloc/vcs/pkg/profile"
)
Expand All @@ -22,6 +23,11 @@ type GetRefreshStateResponse struct {
RefreshServiceType ServiceType `json:"refreshServiceType"`
}

type GetRefreshedCredentialResponse struct {
Credential *verifiable.Credential
IssuerURL string
}

type Event struct {
WebHook string `json:"webHook,omitempty"`
ProfileID string `json:"profileID,omitempty"`
Expand Down
Loading