Skip to content

Commit 1d2a52c

Browse files
authored
Using the default http client for getting public keys (#161)
1 parent d6907ca commit 1d2a52c

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
- [added] The Admin SDK can now read the Firebase/GCP project ID from
99
both `GCLOUD_PROJECT` and `GOOGLE_CLOUD_PROJECT` environment
1010
variables.
11+
- [fixed] Using the default, unauthorized HTTP client to retrieve
12+
public keys when verifying ID tokens.
1113

1214
# v3.1.0
1315

auth/auth.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"encoding/json"
2020
"errors"
2121
"fmt"
22+
"net/http"
2223
"strings"
2324

2425
"golang.org/x/net/context"
@@ -128,7 +129,7 @@ func NewClient(ctx context.Context, conf *internal.AuthConfig) (*Client, error)
128129

129130
return &Client{
130131
is: is,
131-
keySource: newHTTPKeySource(idTokenCertURL, hc),
132+
keySource: newHTTPKeySource(idTokenCertURL, http.DefaultClient),
132133
projectID: conf.ProjectID,
133134
signer: signer,
134135
version: "Go/Admin/" + conf.Version,

auth/token_verifier.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"encoding/json"
2525
"encoding/pem"
2626
"errors"
27+
"fmt"
2728
"io/ioutil"
2829
"net/http"
2930
"strconv"
@@ -98,6 +99,9 @@ func (k *httpKeySource) refreshKeys(ctx context.Context) error {
9899
if err != nil {
99100
return err
100101
}
102+
if resp.StatusCode != http.StatusOK {
103+
return fmt.Errorf("invalid response (%d) while retrieving public keys: %s", resp.StatusCode, string(contents))
104+
}
101105
newKeys, err := parsePublicKeys(contents)
102106
if err != nil {
103107
return err

0 commit comments

Comments
 (0)