...

Source file src/github.com/aws/aws-sdk-go-v2/internal/auth/smithy/bearer_token_signer_adapter.go

Documentation: github.com/aws/aws-sdk-go-v2/internal/auth/smithy

     1  package smithy
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	"github.com/aws/smithy-go"
     8  	"github.com/aws/smithy-go/auth"
     9  	"github.com/aws/smithy-go/auth/bearer"
    10  	smithyhttp "github.com/aws/smithy-go/transport/http"
    11  )
    12  
    13  // BearerTokenSignerAdapter adapts smithy bearer.Signer to smithy http
    14  // auth.Signer.
    15  type BearerTokenSignerAdapter struct {
    16  	Signer bearer.Signer
    17  }
    18  
    19  var _ (smithyhttp.Signer) = (*BearerTokenSignerAdapter)(nil)
    20  
    21  // SignRequest signs the request with the provided bearer token.
    22  func (v *BearerTokenSignerAdapter) SignRequest(ctx context.Context, r *smithyhttp.Request, identity auth.Identity, _ smithy.Properties) error {
    23  	ca, ok := identity.(*BearerTokenAdapter)
    24  	if !ok {
    25  		return fmt.Errorf("unexpected identity type: %T", identity)
    26  	}
    27  
    28  	signed, err := v.Signer.SignWithBearerToken(ctx, ca.Token, r)
    29  	if err != nil {
    30  		return fmt.Errorf("sign request: %w", err)
    31  	}
    32  
    33  	*r = *signed.(*smithyhttp.Request)
    34  	return nil
    35  }
    36  

View as plain text