Skip to content

Commit 56f98e1

Browse files
committed
Use transport.SetHeader() for the static JWT token
1 parent 93e4c80 commit 56f98e1

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

s2s.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
type S2SClientConfig struct {
1717
// JWTToken is the JWT token to use for authentication.
1818
JWTToken string
19-
// JWTSecret is the secret key used to create the JWT token.
19+
// JWTSecret is the secret key used to dynamically create JWT token.
2020
JWTSecret string
2121
// Service is used in the service claim of the JWT token.
2222
Service string
@@ -36,15 +36,14 @@ func S2SClient(cfg *S2SClientConfig) *http.Client {
3636
Transport: transport.Chain(http.DefaultTransport,
3737
traceid.Transport,
3838
transport.SetHeader("User-Agent", fmt.Sprintf("sequence/%s", serviceName)),
39-
transport.If(cfg.JWTSecret != "" || cfg.JWTToken != "",
39+
transport.If(cfg.JWTSecret != "",
4040
transport.SetHeaderFunc("Authorization", func(req *http.Request) string {
41-
token := cfg.JWTToken
42-
if token == "" {
43-
token = S2SToken(cfg.JWTSecret, map[string]any{"service": serviceName})
44-
}
45-
return "BEARER " + token
41+
return "BEARER " + S2SToken(cfg.JWTSecret, map[string]any{"service": serviceName})
4642
}),
4743
),
44+
transport.If(cfg.JWTToken != "",
45+
transport.SetHeader("Authorization", "BEARER "+cfg.JWTToken),
46+
),
4847
transport.If(cfg.AccessKey != "",
4948
transport.SetHeader("X-Access-Key", cfg.AccessKey),
5049
),

0 commit comments

Comments
 (0)