@@ -31,6 +31,7 @@ import (
3131 "github.com/IBM/sarama"
3232 "github.com/google/uuid"
3333 "github.com/lestrrat-go/jwx/v2/jwa"
34+ "github.com/lestrrat-go/jwx/v2/jws"
3435 "github.com/lestrrat-go/jwx/v2/jwt"
3536 "golang.org/x/oauth2"
3637)
@@ -50,6 +51,7 @@ type OAuthTokenSourcePrivateKeyJWT struct {
5051 ClientAssertionKey string
5152 Resource string
5253 Audience string
54+ Kid string
5355}
5456
5557type tokenResponse struct {
@@ -70,6 +72,7 @@ func (m KafkaMetadata) getOAuthTokenSourcePrivateKeyJWT() *OAuthTokenSourcePriva
7072 ClientAssertionKey : m .OidcClientAssertionKey ,
7173 Resource : m .OidcResource ,
7274 Audience : m .OidcAudience ,
75+ Kid : m .OidcKid ,
7376 }
7477}
7578
@@ -166,7 +169,15 @@ func (ts *OAuthTokenSourcePrivateKeyJWT) Token() (*sarama.AccessToken, error) {
166169 return nil , fmt .Errorf ("failed to build token: %w" , err )
167170 }
168171
169- assertion , err := jwt .Sign (token , jwt .WithKey (jwa .RS256 , rsaKey ))
172+ var signOptions []jwt.Option
173+ if ts .Kid != "" {
174+ headers := jws .NewHeaders ()
175+ if err = headers .Set ("kid" , ts .Kid ); err != nil {
176+ return nil , fmt .Errorf ("error setting JWT kid header: %w" , err )
177+ }
178+ signOptions = append (signOptions , jws .WithProtectedHeaders (headers ))
179+ }
180+ assertion , err := jwt .Sign (token , jwt .WithKey (jwa .RS256 , rsaKey , signOptions ... ))
170181 if err != nil {
171182 return nil , fmt .Errorf ("error signing client assertion: %w" , err )
172183 }
0 commit comments