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

AppCheck Admin SDK requires use of internal package externally in its API #572

Open
mattrltrent opened this issue Jul 24, 2023 · 2 comments
Assignees

Comments

@mattrltrent
Copy link

Describe your environment

  • Operating System version: Macbook Pro Apple M1 Ventura 13.4.1 running Dockerized env from golang:1.20-alpine.
  • Firebase SDK version: 4
  • Library version: v4.12.0
  • Firebase Product: Appcheck

Describe the problem

Original Stack Overflow source here.

First, I believe the Firebase documentation for how to use AppCheck with the Golang SDK is wrong here.

It says you need to create a new appcheck.Client directly via method off of your firebase.App, but this method doesn't exist (anymore?):

func main() {
    app, err := firebaseAdmin.NewApp(context.Background(), nil)
    if err != nil {
        log.Fatalf("error initializing app: %v\n", err)
    }

    appCheck, err = app.AppCheck(context.Background()) // <-- here, does not exist
    if err != nil {
        log.Fatalf("error initializing app: %v\n", err)
    }

    http.HandleFunc("/yourApiEndpoint", requireAppCheck(yourApiEndpointHandler))
    log.Fatal(http.ListenAndServe(":8080", nil))
}

So, instead, I've referred to Firebase's appcheck package here which says you now need to create a new instance via this method instead:

func NewClient(ctx context.Context, conf *internal.AppCheckConfig) (*Client, error)

This, in theory, should work. However, note the use of an internal package.

We can try using NewClient(...), and will be able to provide its first arg of context.Context, but won't be able to provide a value for its second arg of type *internal.AppCheckConfig because it's internal.

Steps to reproduce:

import firebase "firebase.google.com/go"

// get the admin app of type *firebase.App
app, err := firebase.NewApp(context.Background(), nil, opt)
if err != nil {
    return err
}

// then try to get the type of *appcheck.Client
appCheck, err := appcheck.NewClient(context.Background(), &internal.AppCheckConfig{ // <-- won't work because using internal package
    ProjectID: "your_proj_id",
})
if err != nil {
    return err
}
@google-oss-bot
Copy link
Collaborator

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

@fis
Copy link

fis commented Jul 29, 2023

The "steps to reproduce" example imports the v1 major version of the module, which did not have an AppCheck method. The v4 major version ("firebase.google.com/go/v4") used by the example in the documentation does (docs).

The example from the documentation builds without errors for me. In an empty directory:

$ cat > main.go
package main

import (
    "context"
    "log"
    "net/http"

    firebaseAdmin "firebase.google.com/go/v4"
    "firebase.google.com/go/v4/appcheck"
)
// ...
// rest of the code from https://firebase.google.com/docs/app-check/custom-resource-backend#go
// ...
$ go mod init example.com/test
go: creating new go.mod: module example.com/test
go: to add module requirements and sums:
$ go mod tidy
go: finding module for package firebase.google.com/go/v4/appcheck
go: finding module for package firebase.google.com/go/v4
go: found firebase.google.com/go/v4 in firebase.google.com/go/v4 v4.12.0
go: found firebase.google.com/go/v4/appcheck in firebase.google.com/go/v4 v4.12.0
$ go build .
// no errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants