Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions internal/creds.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ func Creds(ctx context.Context, ds *DialSettings) (*google.Credentials, error) {
// options provided via [option.ClientOption], including legacy oauth2/google
// options. If there are no applicable options, then it returns the result of
// [cloud.google.com/go/auth/credentials.DetectDefault].
// Note: If NoAuth is true, when [google.golang.org/api/option.WithoutAuthentication]
// is passed, then no authentication will be performed and this function will
// return nil, nil.
func AuthCreds(ctx context.Context, settings *DialSettings) (*auth.Credentials, error) {
if settings.NoAuth {
return nil, nil
}
if settings.AuthCredentials != nil {
return settings.AuthCredentials, nil
}
Expand Down
14 changes: 14 additions & 0 deletions internal/creds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,3 +645,17 @@ func TestIsSelfSignedJWTFlow(t *testing.T) {
}
}
}

func TestNewAuth_NoAuth(t *testing.T) {
ctx := context.Background()
ds := &DialSettings{
NoAuth: true,
}
creds, err := AuthCreds(ctx, ds)
if err != nil {
t.Fatalf("got %v, want nil error", err)
}
if creds != nil {
t.Fatalf("got %v, want nil creds", creds)
}
}
21 changes: 11 additions & 10 deletions option/internaloption/internaloption.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,21 +289,22 @@ func GetLogger(opts []option.ClientOption) *slog.Logger {
// options provided via [option.ClientOption], including legacy oauth2/google
// options, in this order:
//
// * [option.WithAuthCredentials]
// * [option/internaloption.WithCredentials] (internal use only)
// * [option.WithCredentials]
// * [option.WithTokenSource]
// - [option.WithoutAuthentication]
// - [option.WithAuthCredentials]
// - [WithCredentials] (internal use only)
// - [option.WithCredentials]
// - [option.WithTokenSource]
//
// If there are no applicable credentials options, then it passes the
// following options to [cloud.google.com/go/auth/credentials.DetectDefault] and
// returns the result:
//
// * [option.WithAudiences]
// * [option.WithCredentialsFile]
// * [option.WithCredentialsJSON]
// * [option.WithScopes]
// * [option/internaloption.WithDefaultScopes] (internal use only)
// * [option/internaloption.EnableJwtWithScope] (internal use only)
// - [option.WithAudiences]
// - [option.WithCredentialsFile]
// - [option.WithCredentialsJSON]
// - [option.WithScopes]
// - [WithDefaultScopes] (internal use only)
// - [EnableJwtWithScope] (internal use only)
//
// This function should only be used internally by generated clients. This is an
// EXPERIMENTAL API and may be changed or removed in the future.
Expand Down