Source File
idtoken.go
Belonging Package
google.golang.org/api/idtoken
package idtoken
import (
htransport
)
type ClientOption = option.ClientOption
func ( context.Context, string, ...ClientOption) (*http.Client, error) {
var internal.DialSettings
for , := range {
.Apply(&)
}
if := .Validate(); != nil {
return nil,
}
if .NoAuth {
return nil, fmt.Errorf("idtoken: option.WithoutAuthentication not supported")
}
if .APIKey != "" {
return nil, fmt.Errorf("idtoken: option.WithAPIKey not supported")
}
if .TokenSource != nil {
return nil, fmt.Errorf("idtoken: option.WithTokenSource not supported")
}
, := NewTokenSource(, , ...)
if != nil {
return nil,
= append(, option.WithTokenSource(), internaloption.SkipDialSettingsValidation())
, := htransport.NewTransport(, http.DefaultTransport, ...)
if != nil {
return nil,
}
return &http.Client{Transport: }, nil
}
func ( context.Context, string, ...ClientOption) (oauth2.TokenSource, error) {
if == "" {
return nil, fmt.Errorf("idtoken: must supply a non-empty audience")
}
var internal.DialSettings
for , := range {
.Apply(&)
}
if := .Validate(); != nil {
return nil,
}
if .TokenSource != nil {
return nil, fmt.Errorf("idtoken: option.WithTokenSource not supported")
}
if .ImpersonationConfig != nil {
return nil, fmt.Errorf("idtoken: option.WithImpersonatedCredentials not supported")
}
return newTokenSource(, , &)
}
func ( context.Context, string, *internal.DialSettings) (oauth2.TokenSource, error) {
, := internal.Creds(, )
if != nil {
return nil,
}
if len(.JSON) > 0 {
return tokenSourceFromBytes(, .JSON, , )
if metadata.OnGCE() {
return computeTokenSource(, )
}
return nil, fmt.Errorf("idtoken: couldn't find any credentials")
}
func ( context.Context, []byte, string, *internal.DialSettings) (oauth2.TokenSource, error) {
if := isServiceAccount(); != nil {
return nil,
}
, := google.JWTConfigFromJSON(, .Scopes...)
if != nil {
return nil,
}
:= .CustomClaims
if == nil {
= make(map[string]interface{})
}
["target_audience"] =
.PrivateClaims =
.UseIDToken = true
:= .TokenSource()
, := .Token()
if != nil {
return nil,
}
return oauth2.ReuseTokenSource(, ), nil
}
func ( []byte) error {
if len() == 0 {
return fmt.Errorf("idtoken: credential provided is 0 bytes")
}
var struct {
string `json:"type"`
}
if := json.Unmarshal(, &); != nil {
return
}
if . != "service_account" {
return fmt.Errorf("idtoken: credential must be service_account, found %q", .)
}
return nil
}
func ( map[string]interface{}) ClientOption {
return withCustomClaims()
}
type withCustomClaims map[string]interface{}
func ( withCustomClaims) ( *internal.DialSettings) {
.CustomClaims =
}
func ( string) ClientOption {
return option.WithCredentialsFile()
}
func ( []byte) ClientOption {
return option.WithCredentialsJSON()
}
func ( *http.Client) ClientOption {
return option.WithHTTPClient()
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |