Skip to content

Commit 241c293

Browse files
authored
fix: Skipping credential lookup in emulator mode (#459)
1 parent ea909b1 commit 241c293

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

auth/auth.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import (
2525
"time"
2626

2727
"firebase.google.com/go/v4/internal"
28+
"golang.org/x/oauth2"
29+
"google.golang.org/api/option"
2830
"google.golang.org/api/transport"
2931
)
3032

@@ -47,6 +49,10 @@ var reservedClaims = []string{
4749
"exp", "firebase", "iat", "iss", "jti", "nbf", "nonce", "sub",
4850
}
4951

52+
var emulatorToken = &oauth2.Token{
53+
AccessToken: "owner",
54+
}
55+
5056
// Client is the interface for the Firebase auth service.
5157
//
5258
// Client facilitates generating custom JWT tokens for Firebase clients, and verifying ID tokens issued
@@ -114,7 +120,15 @@ func NewClient(ctx context.Context, conf *internal.AuthConfig) (*Client, error)
114120
return nil, err
115121
}
116122

117-
transport, _, err := transport.NewHTTPClient(ctx, conf.Opts...)
123+
var opts []option.ClientOption
124+
if isEmulator {
125+
ts := oauth2.StaticTokenSource(emulatorToken)
126+
opts = append(opts, option.WithTokenSource(ts))
127+
} else {
128+
opts = append(opts, conf.Opts...)
129+
}
130+
131+
transport, _, err := transport.NewHTTPClient(ctx, opts...)
118132
if err != nil {
119133
return nil, err
120134
}

auth/auth_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,15 +296,11 @@ func TestNewClientEmulatorHostEnvVar(t *testing.T) {
296296
os.Setenv(emulatorHostEnvVar, emulatorHost)
297297
defer os.Unsetenv(emulatorHostEnvVar)
298298

299-
conf := &internal.AuthConfig{
300-
Opts: []option.ClientOption{
301-
option.WithoutAuthentication(),
302-
},
303-
}
304-
client, err := NewClient(context.Background(), conf)
299+
client, err := NewClient(context.Background(), &internal.AuthConfig{})
305300
if err != nil {
306301
t.Fatal(err)
307302
}
303+
308304
baseClient := client.baseClient
309305
if baseClient.userManagementEndpoint != idToolkitV1Endpoint {
310306
t.Errorf("baseClient.userManagementEndpoint = %q; want = %q", baseClient.userManagementEndpoint, idToolkitV1Endpoint)
@@ -778,6 +774,7 @@ func TestEmulatorVerifyIDTokenUnreachableEmulator(t *testing.T) {
778774
t.Fatal(err)
779775
}
780776
client.httpClient.Client.Transport = eConnRefusedTransport{}
777+
client.httpClient.RetryConfig = nil
781778
client.isEmulator = true
782779

783780
token := getEmulatedIDToken(nil)
@@ -1239,6 +1236,7 @@ func TestEmulatorVerifySessionCookieUnreachableEmulator(t *testing.T) {
12391236
t.Fatal(err)
12401237
}
12411238
client.httpClient.Client.Transport = eConnRefusedTransport{}
1239+
client.httpClient.RetryConfig = nil
12421240
client.isEmulator = true
12431241

12441242
token := getEmulatedSessionCookie(nil)

0 commit comments

Comments
 (0)