-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
30 lines (27 loc) · 894 Bytes
/
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
// Package proxiap provides methods and structs to handle authentication
// to resources behind Google's Identity-Aware Proxy (IAP).
package proxiap
import (
"context"
"net/http"
)
// NewIapClient returns a new http.Client with a Transport that handles IAP authentication.
// If iapId is empty, it returns nil.
func NewIapClient(ctx context.Context, iapId string) *http.Client {
if len(iapId) > 0 {
return &http.Client{Transport: &IapAuthTransport{
Tokensource: TokensourceInit(ctx, iapId),
}}
}
return nil
}
// SetIapTransport replaces http.Transport in the provided http.Client with
// a one that will handle authentication behind IAP.
// If iapId is empty, it returns the same clie
func SetIapTransport(ctx context.Context, iapId string, client *http.Client) {
if len(iapId) > 0 {
client.Transport = &IapAuthTransport{
Tokensource: TokensourceInit(ctx, iapId),
}
}
}