Skip to content

Commit 3d5e560

Browse files
authored
fix(auth): Migrate IAM SignBlob to IAMCredentials SignBlob (#404)
* Migrate IAM SignBlob to IAMCredentials SignBlob Point all SignBlob to iamcredentials instead of iam * Minor documentation changes Correct and format some contents * Fix a trailing whitespace
1 parent 969e50e commit 3d5e560

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

auth/auth.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ func NewClient(ctx context.Context, conf *internal.AuthConfig) (*Client, error)
138138
// - If the SDK was initialized with service account credentials, uses the private key present in
139139
// the credentials to sign tokens locally.
140140
// - If a service account email was specified during initialization (via firebase.Config struct),
141-
// calls the IAM service with that email to sign tokens remotely. See
142-
// https://cloud.google.com/iam/reference/rest/v1/projects.serviceAccounts/signBlob.
141+
// calls the IAMCredentials service with that email to sign tokens remotely. See
142+
// https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/signBlob.
143143
// - If the code is deployed in the Google App Engine standard environment, uses the App Identity
144144
// service to sign tokens. See https://cloud.google.com/appengine/docs/standard/go/reference#SignBytes.
145145
// - If the code is deployed in a different GCP-managed environment (e.g. Google Compute Engine),

auth/token_generator.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ func (s serviceAccountSigner) Email(ctx context.Context) (string, error) {
143143
return s.clientEmail, nil
144144
}
145145

146-
// iamSigner is a cryptoSigner that signs data by sending them to the remote IAM service. See
147-
// https://cloud.google.com/iam/reference/rest/v1/projects.serviceAccounts/signBlob for details
148-
// regarding the REST API.
146+
// iamSigner is a cryptoSigner that signs data by sending them to the IAMCredentials service. See
147+
// https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/signBlob
148+
// for details regarding the REST API.
149149
//
150-
// The IAM service requires the identity of a service account. This can be specified explicitly
150+
// IAMCredentials requires the identity of a service account. This can be specified explicitly
151151
// at initialization. If not specified iamSigner attempts to discover a service account identity by
152152
// calling the local metadata service (works in environments like Google Compute Engine).
153153
type iamSigner struct {
@@ -169,7 +169,7 @@ func newIAMSigner(ctx context.Context, config *internal.AuthConfig) (*iamSigner,
169169
httpClient: hc,
170170
serviceAcct: config.ServiceAccountID,
171171
metadataHost: "http://metadata.google.internal",
172-
iamHost: "https://iam.googleapis.com",
172+
iamHost: "https://iamcredentials.googleapis.com",
173173
}, nil
174174
}
175175

@@ -181,15 +181,15 @@ func (s iamSigner) Sign(ctx context.Context, b []byte) ([]byte, error) {
181181

182182
url := fmt.Sprintf("%s/v1/projects/-/serviceAccounts/%s:signBlob", s.iamHost, account)
183183
body := map[string]interface{}{
184-
"bytesToSign": base64.StdEncoding.EncodeToString(b),
184+
"payload": base64.StdEncoding.EncodeToString(b),
185185
}
186186
req := &internal.Request{
187187
Method: http.MethodPost,
188188
URL: url,
189189
Body: internal.NewJSONEntity(body),
190190
}
191191
var signResponse struct {
192-
Signature string `json:"signature"`
192+
Signature string `json:"signedBlob"`
193193
}
194194
if _, err := s.httpClient.DoAndUnmarshal(ctx, req, &signResponse); err != nil {
195195
return nil, err

auth/token_generator_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ func TestEncodeToken(t *testing.T) {
6060

6161
if sig, err := base64.RawURLEncoding.DecodeString(parts[2]); err != nil {
6262
t.Fatal(err)
63-
} else if string(sig) != "signature" {
64-
t.Errorf("decode(signature) = %q; want = %q", string(sig), "signature")
63+
} else if string(sig) != "signedBlob" {
64+
t.Errorf("decode(signature) = %q; want = %q", string(sig), "signedBlob")
6565
}
6666
}
6767

@@ -277,12 +277,12 @@ func (s *mockSigner) Sign(ctx context.Context, b []byte) ([]byte, error) {
277277
if s.err != nil {
278278
return nil, s.err
279279
}
280-
return []byte("signature"), nil
280+
return []byte("signedBlob"), nil
281281
}
282282

283283
func iamServer(t *testing.T, serviceAcct, signature string) *httptest.Server {
284284
resp := map[string]interface{}{
285-
"signature": base64.StdEncoding.EncodeToString([]byte(signature)),
285+
"signedBlob": base64.StdEncoding.EncodeToString([]byte(signature)),
286286
}
287287
wantPath := fmt.Sprintf("/v1/projects/-/serviceAccounts/%s:signBlob", serviceAcct)
288288
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -295,8 +295,8 @@ func iamServer(t *testing.T, serviceAcct, signature string) *httptest.Server {
295295
if err := json.Unmarshal(reqBody, &m); err != nil {
296296
t.Fatal(err)
297297
}
298-
if m["bytesToSign"] == "" {
299-
t.Fatal("BytesToSign = empty; want = non-empty")
298+
if m["payload"] == "" {
299+
t.Fatal("payload = empty; want = non-empty")
300300
}
301301
if r.URL.Path != wantPath {
302302
t.Errorf("Path = %q; want = %q", r.URL.Path, wantPath)

0 commit comments

Comments
 (0)