Skip to content

Commit a8dc77f

Browse files
gIthurielcodyoss
authored andcommitted
google: add external account documentation
Adds some documentation to existing public structures for third-party authentication. Change-Id: I756f5cd5619fbd752c028e99176991139fd45c60 GitHub-Last-Rev: c846ea6 GitHub-Pull-Request: #485 Reviewed-on: https://go-review.googlesource.com/c/oauth2/+/301610 Trust: Cody Oss <[email protected]> Trust: Tyler Bui-Palsulich <[email protected]> Reviewed-by: Cody Oss <[email protected]>
1 parent bce0382 commit a8dc77f

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

google/doc.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
// Package google provides support for making OAuth2 authorized and authenticated
66
// HTTP requests to Google APIs. It supports the Web server flow, client-side
7-
// credentials, service accounts, Google Compute Engine service accounts, Google
8-
// App Engine service accounts and workload identity federation from non-Google
9-
// cloud platforms.
7+
// credentials, service accounts, Google Compute Engine service accounts,
8+
// Google App Engine service accounts and workload identity federation
9+
// from non-Google cloud platforms.
1010
//
1111
// A brief overview of the package follows. For more information, please read
1212
// https://developers.google.com/accounts/docs/OAuth2

google/internal/externalaccount/basecredentials.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,34 @@ var now = func() time.Time {
2020

2121
// Config stores the configuration for fetching tokens with external credentials.
2222
type Config struct {
23+
// Audience is the Secure Token Service (STS) audience which contains the resource name for the workload
24+
// identity pool or the workforce pool and the provider identifier in that pool.
2325
Audience string
26+
// SubjectTokenType is the STS token type based on the Oauth2.0 token exchange spec
27+
// e.g. `urn:ietf:params:oauth:token-type:jwt`.
2428
SubjectTokenType string
29+
// TokenURL is the STS token exchange endpoint.
2530
TokenURL string
31+
// TokenInfoURL is the token_info endpoint used to retrieve the account related information (
32+
// user attributes like account identifier, eg. email, username, uid, etc). This is
33+
// needed for gCloud session account identification.
2634
TokenInfoURL string
35+
// ServiceAccountImpersonationURL is the URL for the service account impersonation request. This is only
36+
// required for workload identity pools when APIs to be accessed have not integrated with UberMint.
2737
ServiceAccountImpersonationURL string
38+
// ClientSecret is currently only required if token_info endpoint also
39+
// needs to be called with the generated GCP access token. When provided, STS will be
40+
// called with additional basic authentication using client_id as username and client_secret as password.
2841
ClientSecret string
42+
// ClientID is only required in conjunction with ClientSecret, as described above.
2943
ClientID string
44+
// CredentialSource contains the necessary information to retrieve the token itself, as well
45+
// as some environmental information.
3046
CredentialSource CredentialSource
47+
// QuotaProjectID is injected by gCloud. If the value is non-empty, the Auth libraries
48+
// will set the x-goog-user-project which overrides the project associated with the credentials.
3149
QuotaProjectID string
50+
// Scopes contains the desired scopes for the returned access token.
3251
Scopes []string
3352
}
3453

@@ -66,6 +85,8 @@ type format struct {
6685
}
6786

6887
// CredentialSource stores the information necessary to retrieve the credentials for the STS exchange.
88+
// Either the File or the URL field should be filled, depending on the kind of credential in question.
89+
// The EnvironmentID should start with AWS if being used for an AWS credential.
6990
type CredentialSource struct {
7091
File string `json:"file"`
7192

@@ -107,7 +128,7 @@ type baseCredentialSource interface {
107128
subjectToken() (string, error)
108129
}
109130

110-
// tokenSource is the source that handles external credentials.
131+
// tokenSource is the source that handles external credentials. It is used to retrieve Tokens.
111132
type tokenSource struct {
112133
ctx context.Context
113134
conf *Config

google/internal/externalaccount/clientauth.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ type clientAuthentication struct {
1919
ClientSecret string
2020
}
2121

22+
// InjectAuthentication is used to add authentication to a Secure Token Service exchange
23+
// request. It modifies either the passed url.Values or http.Header depending on the desired
24+
// authentication format.
2225
func (c *clientAuthentication) InjectAuthentication(values url.Values, headers http.Header) {
2326
if c.ClientID == "" || c.ClientSecret == "" || values == nil || headers == nil {
2427
return

google/internal/externalaccount/impersonate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type impersonateTokenSource struct {
3636
scopes []string
3737
}
3838

39-
// Token performs the exchange to get a temporary service account
39+
// Token performs the exchange to get a temporary service account token to allow access to GCP.
4040
func (its impersonateTokenSource) Token() (*oauth2.Token, error) {
4141
reqBody := generateAccessTokenReq{
4242
Lifetime: "3600s",

0 commit comments

Comments
 (0)