Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/public-api/go/client/interceptors.go
2500 views
1
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package client
6
7
import (
8
"context"
9
"fmt"
10
"github.com/bufbuild/connect-go"
11
)
12
13
func AuthorizationInterceptor(token string) connect.Interceptor {
14
interceptor := connect.UnaryInterceptorFunc(func(next connect.UnaryFunc) connect.UnaryFunc {
15
return func(ctx context.Context, req connect.AnyRequest) (connect.AnyResponse, error) {
16
if req.Spec().IsClient {
17
// Send a token with client requests.
18
req.Header().Set("Authorization", fmt.Sprintf("Bearer %s", token))
19
}
20
21
return next(ctx, req)
22
}
23
})
24
25
return interceptor
26
}
27
28