Add --jwt-id flag (#13218)

* add jwt-id flag

* optimize unit test for jwt-id

* Add jwt-id to help text

* gofmt

---------

Co-authored-by: Preston Van Loon <pvanloon@offchainlabs.com>
This commit is contained in:
Brandon Liu
2023-12-06 03:02:25 +08:00
committed by GitHub
parent 705e98e3c3
commit c78d698d89
11 changed files with 117 additions and 6 deletions

View File

@@ -24,6 +24,7 @@ type Endpoint struct {
type AuthorizationData struct {
Method authorization.Method
Value string
JwtId string
}
// Equals compares two endpoints for equality.
@@ -37,7 +38,7 @@ func (e Endpoint) HttpClient() *http.Client {
if e.Auth.Method != authorization.Bearer {
return http.DefaultClient
}
return NewHttpClientWithSecret(e.Auth.Value)
return NewHttpClientWithSecret(e.Auth.Value, e.Auth.JwtId)
}
// Equals compares two authorization data objects for equality.
@@ -112,10 +113,11 @@ func Method(auth string) authorization.Method {
// NewHttpClientWithSecret returns a http client that utilizes
// jwt authentication.
func NewHttpClientWithSecret(secret string) *http.Client {
func NewHttpClientWithSecret(secret, id string) *http.Client {
authTransport := &jwtTransport{
underlyingTransport: http.DefaultTransport,
jwtSecret: []byte(secret),
jwtId: id,
}
return &http.Client{
Timeout: DefaultRPCHTTPTimeout,