Copyright 2020 Google LLC. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

package idtoken

import (
	
	
	

	
	

	
)
computeTokenSource checks if this code is being run on GCE. If it is, it will use the metadata service to build a TokenSource that fetches ID tokens.
func ( string,  *internal.DialSettings) (oauth2.TokenSource, error) {
	if .CustomClaims != nil {
		return nil, fmt.Errorf("idtoken: WithCustomClaims can't be used with the metadata service, please provide a service account if you would like to use this feature")
	}
	 := computeIDTokenSource{
		audience: ,
	}
	,  := .Token()
	if  != nil {
		return nil, 
	}
	return oauth2.ReuseTokenSource(, ), nil
}

type computeIDTokenSource struct {
	audience string
}

func ( computeIDTokenSource) () (*oauth2.Token, error) {
	 := url.Values{}
	.Set("audience", .audience)
	.Set("format", "full")
	 := "instance/service-accounts/default/identity?" + .Encode()
	,  := metadata.Get()
	if  != nil {
		return nil, 
	}
	if  == "" {
		return nil, fmt.Errorf("idtoken: invalid response from metadata service")
	}
	return &oauth2.Token{
		AccessToken: ,
Compute tokens are valid for one hour, leave a little buffer
		Expiry: time.Now().Add(55 * time.Minute),
	}, nil