...

Source file src/google.golang.org/api/idtoken/examples_test.go

Documentation: google.golang.org/api/idtoken

     1  // Copyright 2020 Google LLC.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package idtoken_test
     6  
     7  import (
     8  	"context"
     9  	"net/http"
    10  
    11  	"google.golang.org/api/idtoken"
    12  )
    13  
    14  func ExampleNewTokenSource_setAuthorizationHeader() {
    15  	ctx := context.Background()
    16  	audience := "http://example.com"
    17  	ts, err := idtoken.NewTokenSource(ctx, audience)
    18  	if err != nil {
    19  		// TODO: Handle error.
    20  	}
    21  	token, err := ts.Token()
    22  	if err != nil {
    23  		// TODO: Handle error.
    24  	}
    25  	req, err := http.NewRequest(http.MethodGet, audience, nil)
    26  	if err != nil {
    27  		// TODO: Handle error.
    28  	}
    29  	token.SetAuthHeader(req)
    30  }
    31  

View as plain text