Skip to content

Commit

Permalink
Merge pull request #1538 from aholovko/proxy_support_for_wallet_cli
Browse files Browse the repository at this point in the history
feat: proxy support for wallet cli
  • Loading branch information
aholovko authored Nov 24, 2023
2 parents 2cd24a4 + 39a36ab commit 28cabe0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
3 changes: 3 additions & 0 deletions component/wallet-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ used for this purpose. The following CLI arguments are supported:
--leveldb-path string leveldb path
--mongodb-connection-string string mongodb connection string
--pin string pin for pre-authorized code flow
--proxy-url string proxy url for http client
--qr-code-path string path to file with qr code
--redirect-uri string callback where the authorization code should be sent (default "http://127.0.0.1/callback")
--scopes strings vcs oauth2 scopes (default [openid])
Expand Down Expand Up @@ -145,7 +146,9 @@ Use the `oidc4vp` command to present Verifiable Credential(s) to the Verifier:
-h, --help help for oidc4vp
--leveldb-path string leveldb path
--mongodb-connection-string string mongodb connection string
--proxy-url string proxy url for http client
--qr-code-path string path to file with qr code
--trust-registry-url string Trust Registry URL. If supplied, Wallet will run Verifier verification against Trust Registry
--wallet-did-index int index of wallet did, if not set the most recently created DID is used (default -1)
```
Expand Down
22 changes: 18 additions & 4 deletions component/wallet-cli/cmd/oidc4vci_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"log/slog"
"net/http"
"net/http/cookiejar"
"net/url"
"strings"

"github.com/henvic/httpretty"
Expand Down Expand Up @@ -54,6 +55,7 @@ type oidc4vciCommandFlags struct {
pin string
enableDiscoverableClientID bool
enableTracing bool
proxyURL string
}

func NewOIDC4VCICommand() *cobra.Command {
Expand Down Expand Up @@ -132,16 +134,27 @@ func NewOIDC4VCICommand() *cobra.Command {
return fmt.Errorf("--credential-format not set")
}

httpTransport := &http.Transport{
TLSClientConfig: tlsConfig,
}

if flags.proxyURL != "" {
proxyURL, parseErr := url.Parse(flags.proxyURL)
if parseErr != nil {
return fmt.Errorf("parse proxy url: %w", parseErr)
}

httpTransport.Proxy = http.ProxyURL(proxyURL)
}

cookie, err := cookiejar.New(&cookiejar.Options{})
if err != nil {
return fmt.Errorf("init cookie jar: %w", err)
}

httpClient := &http.Client{
Jar: cookie,
Transport: &http.Transport{
TLSClientConfig: tlsConfig,
},
Jar: cookie,
Transport: httpTransport,
}

if flags.enableTracing {
Expand Down Expand Up @@ -322,6 +335,7 @@ func NewOIDC4VCICommand() *cobra.Command {
cmd.Flags().BoolVar(&flags.enableDiscoverableClientID, "enable-discoverable-client-id", false, "enables discoverable client id scheme for dynamic client registration")

cmd.Flags().BoolVar(&flags.enableTracing, "enable-tracing", false, "enables http tracing")
cmd.Flags().StringVar(&flags.proxyURL, "proxy-url", "", "proxy url for http client")

return cmd
}
Expand Down
20 changes: 17 additions & 3 deletions component/wallet-cli/cmd/oidc4vp_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"fmt"
"log/slog"
"net/http"
"net/url"
"strings"

"github.com/henvic/httpretty"
Expand All @@ -35,6 +36,7 @@ type oidc4vpCommandFlags struct {
enableTracing bool
disableDomainMatching bool
trustRegistryURL string
proxyURL string
}

// NewOIDC4VPCommand returns a new command for running OIDC4VP flow.
Expand Down Expand Up @@ -93,10 +95,21 @@ func NewOIDC4VPCommand() *cobra.Command {
)
}

httpTransport := &http.Transport{
TLSClientConfig: tlsConfig,
}

if flags.proxyURL != "" {
proxyURL, parseErr := url.Parse(flags.proxyURL)
if parseErr != nil {
return fmt.Errorf("parse proxy url: %w", parseErr)
}

httpTransport.Proxy = http.ProxyURL(proxyURL)
}

httpClient := &http.Client{
Transport: &http.Transport{
TLSClientConfig: tlsConfig,
},
Transport: httpTransport,
}

if flags.enableTracing {
Expand Down Expand Up @@ -187,6 +200,7 @@ func createFlags(cmd *cobra.Command, flags *oidc4vpCommandFlags) {
cmd.Flags().StringVar(&flags.trustRegistryURL, "trust-registry-url", "", "Trust Registry URL. If supplied, Wallet will run Verifier verification against Trust Registry")

cmd.Flags().BoolVar(&flags.enableTracing, "enable-tracing", false, "enables http tracing")
cmd.Flags().StringVar(&flags.proxyURL, "proxy-url", "", "proxy url for http client")
}

type oidc4vpProvider struct {
Expand Down

0 comments on commit 28cabe0

Please sign in to comment.