Skip to content

Commit cef91ac

Browse files
Merge dev into master
2 parents 54b8114 + e921fe9 commit cef91ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+2342
-990
lines changed

Diff for: .github/scripts/run_all_tests.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ gpg --quiet --batch --yes --decrypt --passphrase="${FIREBASE_SERVICE_ACCT_KEY}"
2222

2323
echo "${FIREBASE_API_KEY}" > testdata/integration_apikey.txt
2424

25-
go test -v -race firebase.google.com/go/...
25+
go test -v -race ./...

Diff for: .github/workflows/ci.yml

+32-17
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,33 @@ name: Continuous Integration
22
on: pull_request
33
jobs:
44

5-
build:
6-
name: Build
5+
module:
6+
name: Module build
77
runs-on: ubuntu-latest
8-
env:
9-
GOPATH: ${{ github.workspace }}/go
108
strategy:
119
matrix:
1210
go: [1.12, 1.13, 1.14]
13-
steps:
1411

12+
steps:
1513
- name: Set up Go ${{ matrix.go }}
1614
uses: actions/setup-go@v1
1715
with:
1816
go-version: ${{ matrix.go }}
19-
id: go
2017

21-
- name: Check out code into GOPATH
18+
- name: Check out code
2219
uses: actions/checkout@v2
23-
with:
24-
path: go/src/firebase.google.com/go
25-
26-
- name: Get dependencies
27-
run: go get -t -v $(go list ./... | grep -v integration)
2820

2921
- name: Run Linter
3022
run: |
31-
go get golang.org/x/lint/golint
32-
$GOPATH/bin/golint -set_exit_status firebase.google.com/go/...
23+
go get -u golang.org/x/lint/golint
24+
GOLINT=`go list -f {{.Target}} golang.org/x/lint/golint`
25+
$GOLINT -set_exit_status ./...
3326
3427
- name: Run Unit Tests
3528
if: success() || failure()
36-
run: go test -v -race -test.short firebase.google.com/go/...
29+
run: go test -v -race -test.short ./...
3730

3831
- name: Run Formatter
39-
working-directory: ./go/src/firebase.google.com/go
4032
run: |
4133
if [[ ! -z "$(gofmt -l -s .)" ]]; then
4234
echo "Go code is not formatted:"
@@ -45,4 +37,27 @@ jobs:
4537
fi
4638
4739
- name: Run Static Analyzer
48-
run: go vet -v firebase.google.com/go/...
40+
run: go vet -v ./...
41+
42+
gopath:
43+
name: Gopath build
44+
runs-on: ubuntu-latest
45+
env:
46+
GOPATH: ${{ github.workspace }}/go
47+
48+
steps:
49+
- name: Set up Go 1.12
50+
uses: actions/setup-go@v1
51+
with:
52+
go-version: 1.12
53+
54+
- name: Check out code into GOPATH
55+
uses: actions/checkout@v2
56+
with:
57+
path: go/src/firebase.google.com/go
58+
59+
- name: Get dependencies
60+
run: go get -t -v $(go list ./... | grep -v integration)
61+
62+
- name: Run Unit Tests
63+
run: go test -v -race -test.short firebase.google.com/go/...

Diff for: .github/workflows/release.yml

+8-16
Original file line numberDiff line numberDiff line change
@@ -36,34 +36,26 @@ jobs:
3636

3737
runs-on: ubuntu-latest
3838

39-
env:
40-
GOPATH: ${{ github.workspace }}/go
41-
4239
# When manually triggering the build, the requester can specify a target branch or a tag
4340
# via the 'ref' client parameter.
4441
steps:
45-
- name: Check out code into GOPATH
46-
uses: actions/checkout@v2
47-
with:
48-
path: go/src/firebase.google.com/go
49-
ref: ${{ github.event.client_payload.ref || github.ref }}
50-
5142
- name: Set up Go
5243
uses: actions/setup-go@v1
5344
with:
54-
go-version: 1.11
45+
go-version: 1.12
5546

56-
- name: Get dependencies
57-
run: go get -t -v $(go list ./... | grep -v integration)
47+
- name: Check out code
48+
uses: actions/checkout@v2
49+
with:
50+
ref: ${{ github.event.client_payload.ref || github.ref }}
5851

5952
- name: Run Linter
6053
run: |
61-
echo
62-
go get golang.org/x/lint/golint
63-
$GOPATH/bin/golint -set_exit_status firebase.google.com/go/...
54+
go get -u golang.org/x/lint/golint
55+
GOLINT=`go list -f {{.Target}} golang.org/x/lint/golint`
56+
$GOLINT -set_exit_status ./...
6457
6558
- name: Run Tests
66-
working-directory: ./go/src/firebase.google.com/go
6759
run: ./.github/scripts/run_all_tests.sh
6860
env:
6961
FIREBASE_SERVICE_ACCT_KEY: ${{ secrets.FIREBASE_SERVICE_ACCT_KEY }}

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ requests, code review feedback, and also pull requests.
4141

4242
## Supported Go Versions
4343

44-
We support Go v1.11 and higher.
44+
We support Go v1.12 and higher.
4545
[Continuous integration](https://github.com/firebase/firebase-admin-go/actions) system
46-
tests the code on Go v1.11 through v1.13.
46+
tests the code on Go v1.12 through v1.14.
4747

4848
## Documentation
4949

Diff for: auth/auth.go

+61-5
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,19 @@ import (
2323
"strings"
2424
"time"
2525

26-
"firebase.google.com/go/internal"
26+
"firebase.google.com/go/v4/internal"
2727
"google.golang.org/api/transport"
2828
)
2929

3030
const (
31+
authErrorCode = "authErrorCode"
3132
firebaseAudience = "https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit"
3233
oneHourInSeconds = 3600
34+
35+
// SDK-generated error codes
36+
idTokenRevoked = "ID_TOKEN_REVOKED"
37+
sessionCookieRevoked = "SESSION_COOKIE_REVOKED"
38+
tenantIDMismatch = "TENANT_ID_MISMATCH"
3339
)
3440

3541
var reservedClaims = []string{
@@ -102,7 +108,6 @@ func NewClient(ctx context.Context, conf *internal.AuthConfig) (*Client, error)
102108

103109
hc := internal.WithDefaultRetryConfig(transport)
104110
hc.CreateErrFn = handleHTTPError
105-
hc.SuccessFn = internal.HasSuccessStatus
106111
hc.Opts = []internal.HTTPOption{
107112
internal.WithHeader("X-Client-Version", fmt.Sprintf("Go/Admin/%s", conf.Version)),
108113
}
@@ -261,12 +266,23 @@ func (c *baseClient) withTenantID(tenantID string) *baseClient {
261266
func (c *baseClient) VerifyIDToken(ctx context.Context, idToken string) (*Token, error) {
262267
decoded, err := c.idTokenVerifier.VerifyToken(ctx, idToken)
263268
if err == nil && c.tenantID != "" && c.tenantID != decoded.Firebase.Tenant {
264-
return nil, internal.Errorf(tenantIDMismatch, "invalid tenant id: %q", decoded.Firebase.Tenant)
269+
return nil, &internal.FirebaseError{
270+
ErrorCode: internal.InvalidArgument,
271+
String: fmt.Sprintf("invalid tenant id: %q", decoded.Firebase.Tenant),
272+
Ext: map[string]interface{}{
273+
authErrorCode: tenantIDMismatch,
274+
},
275+
}
265276
}
266277

267278
return decoded, err
268279
}
269280

281+
// IsTenantIDMismatch checks if the given error was due to a mismatched tenant ID in a JWT.
282+
func IsTenantIDMismatch(err error) bool {
283+
return hasAuthErrorCode(err, tenantIDMismatch)
284+
}
285+
270286
// VerifyIDTokenAndCheckRevoked verifies the provided ID token, and additionally checks that the
271287
// token has not been revoked.
272288
//
@@ -284,12 +300,27 @@ func (c *baseClient) VerifyIDTokenAndCheckRevoked(ctx context.Context, idToken s
284300
if err != nil {
285301
return nil, err
286302
}
303+
287304
if revoked {
288-
return nil, internal.Error(idTokenRevoked, "ID token has been revoked")
305+
return nil, &internal.FirebaseError{
306+
ErrorCode: internal.InvalidArgument,
307+
String: "ID token has been revoked",
308+
Ext: map[string]interface{}{
309+
authErrorCode: idTokenRevoked,
310+
},
311+
}
289312
}
313+
290314
return decoded, nil
291315
}
292316

317+
// IsIDTokenRevoked checks if the given error was due to a revoked ID token.
318+
//
319+
// When IsIDTokenRevoked returns true, IsIDTokenInvalid is guranteed to return true.
320+
func IsIDTokenRevoked(err error) bool {
321+
return hasAuthErrorCode(err, idTokenRevoked)
322+
}
323+
293324
// VerifySessionCookie verifies the signature and payload of the provided Firebase session cookie.
294325
//
295326
// VerifySessionCookie accepts a signed JWT token string, and verifies that it is current, issued for the
@@ -324,12 +355,27 @@ func (c *Client) VerifySessionCookieAndCheckRevoked(ctx context.Context, session
324355
if err != nil {
325356
return nil, err
326357
}
358+
327359
if revoked {
328-
return nil, internal.Error(sessionCookieRevoked, "session cookie has been revoked")
360+
return nil, &internal.FirebaseError{
361+
ErrorCode: internal.InvalidArgument,
362+
String: "session cookie has been revoked",
363+
Ext: map[string]interface{}{
364+
authErrorCode: sessionCookieRevoked,
365+
},
366+
}
329367
}
368+
330369
return decoded, nil
331370
}
332371

372+
// IsSessionCookieRevoked checks if the given error was due to a revoked session cookie.
373+
//
374+
// When IsSessionCookieRevoked returns true, IsSessionCookieInvalid is guranteed to return true.
375+
func IsSessionCookieRevoked(err error) bool {
376+
return hasAuthErrorCode(err, sessionCookieRevoked)
377+
}
378+
333379
func (c *baseClient) checkRevoked(ctx context.Context, token *Token) (bool, error) {
334380
user, err := c.GetUser(ctx, token.UID)
335381
if err != nil {
@@ -338,3 +384,13 @@ func (c *baseClient) checkRevoked(ctx context.Context, token *Token) (bool, erro
338384

339385
return token.IssuedAt*1000 < user.TokensValidAfterMillis, nil
340386
}
387+
388+
func hasAuthErrorCode(err error, code string) bool {
389+
fe, ok := err.(*internal.FirebaseError)
390+
if !ok {
391+
return false
392+
}
393+
394+
got, ok := fe.Ext[authErrorCode]
395+
return ok && got == code
396+
}

Diff for: auth/auth_appengine.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package auth
1919
import (
2020
"context"
2121

22-
"firebase.google.com/go/internal"
22+
"firebase.google.com/go/v4/internal"
2323
"google.golang.org/appengine"
2424
)
2525

Diff for: auth/auth_std.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
// See the License for the specific language governing permissions and
1515
// limitations under the License.
1616

17-
package auth // import "firebase.google.com/go/auth"
17+
package auth
1818

1919
import (
2020
"context"
2121

22-
"firebase.google.com/go/internal"
22+
"firebase.google.com/go/v4/internal"
2323
)
2424

2525
func newCryptoSigner(ctx context.Context, conf *internal.AuthConfig) (cryptoSigner, error) {

0 commit comments

Comments
 (0)