Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
43c7e77
chore: Removed Travis CI integration (#326)
hiranya911 Jan 16, 2020
aa4e7a4
chore: Added Actions-based release workflow (#331)
hiranya911 Feb 19, 2020
0e690ec
chore: Running CI workflow on pull_request (#338)
hiranya911 Feb 25, 2020
7c2199d
fix(fcm): correct the iidEndpoint endpoints used for topic management…
rueian Feb 25, 2020
cdf28fb
fix(fcm): Fix documents of FCM batch request limit (#347)
178inaba Mar 9, 2020
a199c4a
Renamed WebpushFcmOptions to WebpushFCMOptions (#334)
hiranya911 Feb 20, 2020
afbb294
Added modules support; Added semantic import versioning (#336)
hiranya911 Feb 21, 2020
4a8be36
feat: New error handling APIs (#342)
hiranya911 Mar 4, 2020
882fcd0
FCM error handling revamp (#343)
hiranya911 Mar 6, 2020
afc8ff2
RTDB error handling revamp (#345)
hiranya911 Mar 10, 2020
3fd94a2
Error handling revamp of Auth APIs (#348)
hiranya911 Mar 12, 2020
b7b5248
Error handling support in the token verification APIs (#349)
hiranya911 Mar 16, 2020
188dcfa
Removing deprecated HTTP and error handling utils (#350)
hiranya911 Mar 18, 2020
0f3e32f
Handling timeouts, connection and other network errors (#353)
hiranya911 Mar 19, 2020
df1279d
Merge branch 'dev' into v4
hiranya911 May 6, 2020
995c845
Removing old release workflow files
hiranya911 May 6, 2020
4ab0e6f
Removing old release workflow files
hiranya911 May 6, 2020
82d0ba0
Removing an erroneous import
hiranya911 May 6, 2020
f232300
Merge branch 'dev' into v4
hiranya911 May 26, 2020
437a7c4
Fixed bad merge
hiranya911 May 26, 2020
9cd03af
Merge branch 'dev' into v4
hiranya911 Jun 5, 2020
fcdf800
Fixed failing test due to old dependency
hiranya911 Jun 5, 2020
beaa6ae
chore: Updated release flow for modules support (#378)
hiranya911 Jun 9, 2020
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
2 changes: 1 addition & 1 deletion .github/scripts/run_all_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ gpg --quiet --batch --yes --decrypt --passphrase="${FIREBASE_SERVICE_ACCT_KEY}"

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

go test -v -race firebase.google.com/go/...
go test -v -race ./...
22 changes: 7 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,30 @@ jobs:
build:
name: Build
runs-on: ubuntu-latest
env:
GOPATH: ${{ github.workspace }}/go
strategy:
matrix:
go: [1.12, 1.13, 1.14]
steps:

steps:
- name: Set up Go ${{ matrix.go }}
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go }}
id: go

- name: Check out code into GOPATH
- name: Check out code
uses: actions/checkout@v2
with:
path: go/src/firebase.google.com/go

- name: Get dependencies
run: go get -t -v $(go list ./... | grep -v integration)

- name: Run Linter
run: |
go get golang.org/x/lint/golint
$GOPATH/bin/golint -set_exit_status firebase.google.com/go/...
go get -u golang.org/x/lint/golint
GOLINT=`go list -f {{.Target}} golang.org/x/lint/golint`
$GOLINT -set_exit_status ./...

- name: Run Unit Tests
if: success() || failure()
run: go test -v -race -test.short firebase.google.com/go/...
run: go test -v -race -test.short ./...

- name: Run Formatter
working-directory: ./go/src/firebase.google.com/go
run: |
if [[ ! -z "$(gofmt -l -s .)" ]]; then
echo "Go code is not formatted:"
Expand All @@ -45,4 +37,4 @@ jobs:
fi

- name: Run Static Analyzer
run: go vet -v firebase.google.com/go/...
run: go vet -v ./...
24 changes: 8 additions & 16 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,34 +36,26 @@ jobs:

runs-on: ubuntu-latest

env:
GOPATH: ${{ github.workspace }}/go

# When manually triggering the build, the requester can specify a target branch or a tag
# via the 'ref' client parameter.
steps:
- name: Check out code into GOPATH
uses: actions/checkout@v2
with:
path: go/src/firebase.google.com/go
ref: ${{ github.event.client_payload.ref || github.ref }}

- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.11
go-version: 1.12

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

- name: Run Linter
run: |
echo
go get golang.org/x/lint/golint
$GOPATH/bin/golint -set_exit_status firebase.google.com/go/...
go get -u golang.org/x/lint/golint
GOLINT=`go list -f {{.Target}} golang.org/x/lint/golint`
$GOLINT -set_exit_status ./...

- name: Run Tests
working-directory: ./go/src/firebase.google.com/go
run: ./.github/scripts/run_all_tests.sh
env:
FIREBASE_SERVICE_ACCT_KEY: ${{ secrets.FIREBASE_SERVICE_ACCT_KEY }}
Expand Down
66 changes: 61 additions & 5 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@ import (
"strings"
"time"

"firebase.google.com/go/internal"
"firebase.google.com/go/v4/internal"
"google.golang.org/api/transport"
)

const (
authErrorCode = "authErrorCode"
firebaseAudience = "https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit"
oneHourInSeconds = 3600

// SDK-generated error codes
idTokenRevoked = "ID_TOKEN_REVOKED"
sessionCookieRevoked = "SESSION_COOKIE_REVOKED"
tenantIDMismatch = "TENANT_ID_MISMATCH"
)

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

hc := internal.WithDefaultRetryConfig(transport)
hc.CreateErrFn = handleHTTPError
hc.SuccessFn = internal.HasSuccessStatus
hc.Opts = []internal.HTTPOption{
internal.WithHeader("X-Client-Version", fmt.Sprintf("Go/Admin/%s", conf.Version)),
}
Expand Down Expand Up @@ -261,12 +266,23 @@ func (c *baseClient) withTenantID(tenantID string) *baseClient {
func (c *baseClient) VerifyIDToken(ctx context.Context, idToken string) (*Token, error) {
decoded, err := c.idTokenVerifier.VerifyToken(ctx, idToken)
if err == nil && c.tenantID != "" && c.tenantID != decoded.Firebase.Tenant {
return nil, internal.Errorf(tenantIDMismatch, "invalid tenant id: %q", decoded.Firebase.Tenant)
return nil, &internal.FirebaseError{
ErrorCode: internal.InvalidArgument,
String: fmt.Sprintf("invalid tenant id: %q", decoded.Firebase.Tenant),
Ext: map[string]interface{}{
authErrorCode: tenantIDMismatch,
},
}
}

return decoded, err
}

// IsTenantIDMismatch checks if the given error was due to a mismatched tenant ID in a JWT.
func IsTenantIDMismatch(err error) bool {
return hasAuthErrorCode(err, tenantIDMismatch)
}

// VerifyIDTokenAndCheckRevoked verifies the provided ID token, and additionally checks that the
// token has not been revoked.
//
Expand All @@ -284,12 +300,27 @@ func (c *baseClient) VerifyIDTokenAndCheckRevoked(ctx context.Context, idToken s
if err != nil {
return nil, err
}

if revoked {
return nil, internal.Error(idTokenRevoked, "ID token has been revoked")
return nil, &internal.FirebaseError{
ErrorCode: internal.InvalidArgument,
String: "ID token has been revoked",
Ext: map[string]interface{}{
authErrorCode: idTokenRevoked,
},
}
}

return decoded, nil
}

// IsIDTokenRevoked checks if the given error was due to a revoked ID token.
//
// When IsIDTokenRevoked returns true, IsIDTokenInvalid is guranteed to return true.
func IsIDTokenRevoked(err error) bool {
return hasAuthErrorCode(err, idTokenRevoked)
}

// VerifySessionCookie verifies the signature and payload of the provided Firebase session cookie.
//
// VerifySessionCookie accepts a signed JWT token string, and verifies that it is current, issued for the
Expand Down Expand Up @@ -324,12 +355,27 @@ func (c *Client) VerifySessionCookieAndCheckRevoked(ctx context.Context, session
if err != nil {
return nil, err
}

if revoked {
return nil, internal.Error(sessionCookieRevoked, "session cookie has been revoked")
return nil, &internal.FirebaseError{
ErrorCode: internal.InvalidArgument,
String: "session cookie has been revoked",
Ext: map[string]interface{}{
authErrorCode: sessionCookieRevoked,
},
}
}

return decoded, nil
}

// IsSessionCookieRevoked checks if the given error was due to a revoked session cookie.
//
// When IsSessionCookieRevoked returns true, IsSessionCookieInvalid is guranteed to return true.
func IsSessionCookieRevoked(err error) bool {
return hasAuthErrorCode(err, sessionCookieRevoked)
}

func (c *baseClient) checkRevoked(ctx context.Context, token *Token) (bool, error) {
user, err := c.GetUser(ctx, token.UID)
if err != nil {
Expand All @@ -338,3 +384,13 @@ func (c *baseClient) checkRevoked(ctx context.Context, token *Token) (bool, erro

return token.IssuedAt*1000 < user.TokensValidAfterMillis, nil
}

func hasAuthErrorCode(err error, code string) bool {
fe, ok := err.(*internal.FirebaseError)
if !ok {
return false
}

got, ok := fe.Ext[authErrorCode]
return ok && got == code
}
2 changes: 1 addition & 1 deletion auth/auth_appengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package auth
import (
"context"

"firebase.google.com/go/internal"
"firebase.google.com/go/v4/internal"
"google.golang.org/appengine"
)

Expand Down
2 changes: 1 addition & 1 deletion auth/auth_std.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package auth // import "firebase.google.com/go/auth"
import (
"context"

"firebase.google.com/go/internal"
"firebase.google.com/go/v4/internal"
)

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