Movatterモバイル変換


[0]ホーム

URL:


idtoken

package
v0.257.0Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2025 License:BSD-3-ClauseImports:27Imported by:445

Details

Repository

github.com/googleapis/google-api-go-client

Links

Documentation

Overview

Package idtoken provides utilities for creating authenticated transports withID Tokens for Google HTTP APIs. It also provides methods to validate Googleissued ID tokens.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

funcNewClient

func NewClient(ctxcontext.Context, audiencestring, opts ...ClientOption) (*http.Client,error)

NewClient creates a HTTP Client that automatically adds an ID token to eachrequest via an Authorization header. The token will have the audienceprovided and be configured with the supplied options. The parameter audiencemay not be empty.

funcNewTokenSource

func NewTokenSource(ctxcontext.Context, audiencestring, opts ...ClientOption) (oauth2.TokenSource,error)

NewTokenSource creates a TokenSource that returns ID tokens with the audienceprovided and configured with the supplied options. The parameter audience maynot be empty.

Example (SetAuthorizationHeader)
package mainimport ("context""net/http""google.golang.org/api/idtoken")func main() {ctx := context.Background()audience := "http://example.com"ts, err := idtoken.NewTokenSource(ctx, audience)if err != nil {// TODO: Handle error.}token, err := ts.Token()if err != nil {// TODO: Handle error.}req, err := http.NewRequest(http.MethodGet, audience, nil)if err != nil {// TODO: Handle error.}token.SetAuthHeader(req)}

Types

typeClientOption

type ClientOption =option.ClientOption

ClientOption is for configuring a Google API client or transport.

funcWithCredentialsFile

func WithCredentialsFile(filenamestring)ClientOption

WithCredentialsFile returns a ClientOption that authenticatesAPI calls with the given service account or refresh token JSONcredentials file.

funcWithCredentialsJSON

func WithCredentialsJSON(p []byte)ClientOption

WithCredentialsJSON returns a ClientOption that authenticatesAPI calls with the given service account or refresh token JSONcredentials.

funcWithCustomClaims

func WithCustomClaims(customClaims map[string]interface{})ClientOption

WithCustomClaims optionally specifies custom private claims for an ID token.

funcWithHTTPClient

func WithHTTPClient(client *http.Client)ClientOption

WithHTTPClient returns a ClientOption that specifies the HTTP client to useas the basis of communications. This option may only be used with servicesthat support HTTP as their communication transport. When used, theWithHTTPClient option takes precedent over all other supplied options.

typePayload

type Payload struct {Issuerstring                 `json:"iss"`Audiencestring                 `json:"aud"`Expiresint64                  `json:"exp"`IssuedAtint64                  `json:"iat"`Subjectstring                 `json:"sub,omitempty"`Claims   map[string]interface{} `json:"-"`}

Payload represents a decoded payload of an ID Token.

funcParsePayloadadded inv0.141.0

func ParsePayload(idTokenstring) (*Payload,error)

ParsePayload parses the given token and returns its payload.

Warning: This function does not validate the token prior to parsing it.

ParsePayload is primarily meant to be used to inspect a token's payload. This isuseful when validation fails and the payload needs to be inspected.

Note: A successful Validate() invocation with the same token will return anidentical payload.

funcValidate

func Validate(ctxcontext.Context, idTokenstring, audiencestring) (*Payload,error)

Validate is used to validate the provided idToken with a known Google certURL. If audience is not empty the audience claim of the Token is validated.Upon successful validation a parsed token Payload is returned allowing thecaller to validate any additional claims.

typeValidator

type Validator struct {// contains filtered or unexported fields}

Validator provides a way to validate Google ID Tokens with a user providedhttp.Client.

funcNewValidator

func NewValidator(ctxcontext.Context, opts ...ClientOption) (*Validator,error)

NewValidator creates a Validator that uses the options provided to configurea the internal http.Client that will be used to make requests to fetch JWKs.

func (*Validator)Validate

func (v *Validator) Validate(ctxcontext.Context, idTokenstring, audiencestring) (*Payload,error)

Validate is used to validate the provided idToken with a known Google certURL. If audience is not empty the audience claim of the Token is validated.Upon successful validation a parsed token Payload is returned allowing thecaller to validate any additional claims.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp