[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(appcheck): Add App Check token verification #484

Merged
merged 20 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Remove JWKSUrl config option.
  • Loading branch information
bamnet committed Oct 21, 2022
commit 4e87e6e79a4d5f66e727be0deefe2b027cc7b638
4 changes: 2 additions & 2 deletions appcheck/appcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

// JWKSUrl is the URL of the JWKS used to verify App Check tokens.
const JWKSUrl = "https://firebaseappcheck.googleapis.com/v1beta/jwks"
var JWKSUrl = "https://firebaseappcheck.googleapis.com/v1beta/jwks"

const appCheckIssuer = "https://firebaseappcheck.googleapis.com/"

Expand Down Expand Up @@ -74,7 +74,7 @@ type Client struct {
// the App Check service through firebase.App.
func NewClient(ctx context.Context, conf *internal.AppCheckConfig) (*Client, error) {
// TODO: Add support for overriding the HTTP client using the App one.
jwks, err := keyfunc.Get(conf.JWKSUrl, keyfunc.Options{
jwks, err := keyfunc.Get(JWKSUrl, keyfunc.Options{
Ctx: ctx,
RefreshInterval: 6 * time.Hour,
})
Expand Down
6 changes: 3 additions & 3 deletions appcheck/appcheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ func TestVerifyTokenHasValidClaims(t *testing.T) {
t.Fatalf("Error loading private key: %v", err)
}

JWKSUrl = ts.URL
conf := &internal.AppCheckConfig{
ProjectID: "project_id",
JWKSUrl: ts.URL,
}

client, err := NewClient(context.Background(), conf)
Expand Down Expand Up @@ -175,9 +175,9 @@ func TestVerifyTokenMustExist(t *testing.T) {
}
defer ts.Close()

JWKSUrl = ts.URL
conf := &internal.AppCheckConfig{
ProjectID: "project_id",
JWKSUrl: ts.URL,
}

client, err := NewClient(context.Background(), conf)
Expand Down Expand Up @@ -208,9 +208,9 @@ func TestVerifyTokenNotExpired(t *testing.T) {
t.Fatalf("Error loading private key: %v", err)
}

JWKSUrl = ts.URL
conf := &internal.AppCheckConfig{
ProjectID: "project_id",
JWKSUrl: ts.URL,
}

client, err := NewClient(context.Background(), conf)
Expand Down
1 change: 0 additions & 1 deletion firebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ func (a *App) Messaging(ctx context.Context) (*messaging.Client, error) {
func (a *App) AppCheck(ctx context.Context) (*appcheck.Client, error) {
conf := &internal.AppCheckConfig{
ProjectID: a.projectID,
JWKSUrl: appcheck.JWKSUrl,
}
return appcheck.NewClient(ctx, conf)
}
Expand Down
1 change: 0 additions & 1 deletion internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ type MessagingConfig struct {
// AppCheckConfig represents the configuration of App Check service.
type AppCheckConfig struct {
ProjectID string
JWKSUrl string
}

// MockTokenSource is a TokenSource implementation that can be used for testing.
Expand Down