Skip to content

Commit

Permalink
add client id
Browse files Browse the repository at this point in the history
  • Loading branch information
wistefan committed Dec 5, 2023
1 parent e18a6e2 commit 988b933
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ type M2M struct {
CredentialPath string `mapstructure:"credentialPath"`
// verification method to be provided for the ld-proof
VerificationMethod string `mapstructure:"verificationMethod"`
// id of the verifier when retrieving tokens
ClientId string `mapstructure:"clientId"`
}

// logging config
Expand Down
2 changes: 2 additions & 0 deletions tir/authorizationClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type HttpGetClient interface {
type AuthorizingHttpClient struct {
httpClient HttpClient
tokenProvider TokenProvider
clientId string
}

type NoAuthHttpClient struct {
Expand Down Expand Up @@ -159,6 +160,7 @@ func (ac AuthorizingHttpClient) postVpToken(tokenEndpoint string, vpToken string
formRequest.Add("vp_token", vpToken)
formRequest.Add("presentation_submission", presentationSubmission)
formRequest.Add("scope", scope)
formRequest.Add("client_id", ac.clientId)

logging.Log().Infof("Get token from %s.", tokenEndpoint)
tokenHttpRequest, err := http.NewRequest("POST", tokenEndpoint, strings.NewReader(formRequest.Encode()))
Expand Down
7 changes: 4 additions & 3 deletions tir/tirClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/bxcodec/httpcache"
"github.com/fiware/VCVerifier/config"
"github.com/fiware/VCVerifier/logging"
)

Expand Down Expand Up @@ -75,7 +76,7 @@ type Claim struct {
AllowedValues []interface{} `json:"allowedValues"`
}

func NewTirHttpClient(tokenProvider TokenProvider, enableAuth bool) (client TirClient, err error) {
func NewTirHttpClient(tokenProvider TokenProvider, config *config.M2M) (client TirClient, err error) {

httpClient := &http.Client{}
_, err = httpcache.NewWithInmemoryCache(httpClient, true, time.Second*60)
Expand All @@ -84,9 +85,9 @@ func NewTirHttpClient(tokenProvider TokenProvider, enableAuth bool) (client TirC
return
}
var httpGetClient HttpGetClient
if enableAuth {
if config.AuthEnabled {
logging.Log().Infof("Provider is %v", tokenProvider)
httpGetClient = AuthorizingHttpClient{httpClient: httpClient, tokenProvider: tokenProvider}
httpGetClient = AuthorizingHttpClient{httpClient: httpClient, tokenProvider: tokenProvider, clientId: config.ClientId}
} else {
httpGetClient = NoAuthHttpClient{httpClient: httpClient}
}
Expand Down
2 changes: 1 addition & 1 deletion verifier/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func InitVerifier(config *configModel.Configuration, ssiKitClient ssikit.SSIKit)
logging.Log().Infof("Auth disabled.")
}

tirClient, err := tir.NewTirHttpClient(tokenProvider, (&config.M2M).AuthEnabled)
tirClient, err := tir.NewTirHttpClient(tokenProvider, &config.M2M)
if err != nil {
logging.Log().Errorf("Was not able to instantiate the trusted-issuers-registry client. Err: %v", err)
return err
Expand Down

0 comments on commit 988b933

Please sign in to comment.