Path: blob/main/components/public-api/go/client/interceptors.go
2500 views
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package client56import (7"context"8"fmt"9"github.com/bufbuild/connect-go"10)1112func AuthorizationInterceptor(token string) connect.Interceptor {13interceptor := connect.UnaryInterceptorFunc(func(next connect.UnaryFunc) connect.UnaryFunc {14return func(ctx context.Context, req connect.AnyRequest) (connect.AnyResponse, error) {15if req.Spec().IsClient {16// Send a token with client requests.17req.Header().Set("Authorization", fmt.Sprintf("Bearer %s", token))18}1920return next(ctx, req)21}22})2324return interceptor25}262728