Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

feat: vcwallet command controller - expire token option #2848

Merged
merged 1 commit into from
Jun 24, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 17 additions & 1 deletion pkg/controller/command/vcwallet/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"fmt"
"io"
"net/http"
"time"

"github.com/piprate/json-gold/ld"

Expand Down Expand Up @@ -109,6 +110,8 @@ const (
logUserIDKey = "userID"

emptyRawLength = 4

defaultTokenExpiry = 5 * time.Minute
)

// AuthCapabilityProvider is for providing Authorization Capabilities (ZCAP-LD) feature for
Expand Down Expand Up @@ -138,6 +141,9 @@ type Config struct {
EDVBatchEndpointExtensionEnabled bool
// Aries Web KMS cache size configuration.
WebKMSCacheSize int
// Default token expiry for all wallet profiles created.
// Will be used only if wallet unlock request doesn't supply default timeout value.
DefaultTokenExpiry time.Duration
}

// provider contains dependencies for the verifiable credential wallet command controller
Expand All @@ -163,6 +169,10 @@ func New(p provider, config *Config) *Command {
cmd.config = config
}

if cmd.config.DefaultTokenExpiry == 0 {
cmd.config.DefaultTokenExpiry = defaultTokenExpiry
}

return cmd
}

Expand Down Expand Up @@ -772,7 +782,13 @@ func prepareUnlockOptions(rqst *UnlockWalletRequest, conf *Config) ([]wallet.Unl
edvOpts = append(edvOpts, edv.WithFullDocumentsReturnedFromQueries())
}

options = append(options, wallet.WithUnlockWebKMSOptions(webkmsOpts...), wallet.WithUnlockEDVOptions(edvOpts...))
tokenExpiry := conf.DefaultTokenExpiry
if rqst.Expiry > 0 {
tokenExpiry = rqst.Expiry
}

options = append(options, wallet.WithUnlockWebKMSOptions(webkmsOpts...), wallet.WithUnlockEDVOptions(edvOpts...),
wallet.WithUnlockExpiry(tokenExpiry))

return options, nil
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/command/vcwallet/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"net/http"
"strings"
"testing"
"time"

"github.com/google/uuid"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -655,6 +656,7 @@ func TestCommand_OpenAndClose(t *testing.T) {
request := &UnlockWalletRequest{
UserID: sampleUser2,
WebKMSAuth: &UnlockAuth{Capability: sampleFakeCapability},
Expiry: 10 * time.Second,
}

// unlock wallet
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/command/vcwallet/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package vcwallet

import (
"encoding/json"
"time"

"github.com/hyperledger/aries-framework-go/pkg/doc/verifiable"
"github.com/hyperledger/aries-framework-go/pkg/kms"
Expand Down Expand Up @@ -66,6 +67,9 @@ type UnlockWalletRequest struct {
// Options for authorizing access to wallet's EDV content store.
// Optional, to be used only if profile for this wallet user is setup to use EDV as content store.
EDVUnlock *UnlockAuth `json:"edvUnlocks"`

// Time duration in milliseconds after which wallet will expire its unlock status.
Expiry time.Duration `json:"expiry,omitempty"`
}

// UnlockAuth contains different options for authorizing access to wallet's EDV content store & webkms.
Expand Down