-
Notifications
You must be signed in to change notification settings - Fork 84
/
jwt_token_client.go
34 lines (28 loc) · 1.1 KB
/
jwt_token_client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package systemfetcher
import (
"net/http"
"github.com/kyma-incubator/compass/components/director/pkg/auth"
"github.com/kyma-incubator/compass/components/director/pkg/credloader"
)
type jwtTokenClient struct {
keyCache credloader.KeysCache
jwtSelfSignCertSecretName string
c *http.Client
}
// NewJwtTokenClient creates a jwt token client
func NewJwtTokenClient(keyCache credloader.KeysCache, jwtSelfSignCertSecretName string, client *http.Client) *jwtTokenClient {
return &jwtTokenClient{
keyCache: keyCache,
jwtSelfSignCertSecretName: jwtSelfSignCertSecretName,
c: client,
}
}
// Do executes a request for jwtTokenClient
func (jtc *jwtTokenClient) Do(req *http.Request, tenant string) (*http.Response, error) {
req = req.WithContext(auth.SaveToContext(req.Context(), &auth.SelfSignedTokenCredentials{
KeysCache: jtc.keyCache,
JwtSelfSignCertSecretName: jtc.jwtSelfSignCertSecretName,
Claims: map[string]interface{}{auth.CustomerIDClaimKey: tenant},
}))
return jtc.c.Do(req)
}