firebase / firebase/firebase-admin-go
AppCheck Admin SDK requires use of internal package externally in its API
- Dominant language
- Go
- Stars
- 1.3k
- Forks
- 274
- Avg merge
- 10h 39m
- Merged PRs (30d)
- 2
Description
### 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](https://pkg.go.dev/firebase.google.com/go/v4@v4.12.0/appcheck?tab=versions)
* Firebase Product: [Appcheck](https://pkg.go.dev/firebase.google.com/go/v4@v4.12.0/appcheck)
### Describe the problem
Original Stack Overflow source [here](https://stackoverflow.com/questions/76746229/firebase-appcheck-golang-admin-sdk-requires-use-of-internal-package-externally-i).
First, I believe the Firebase documentation for how to use AppCheck with the Golang SDK is wrong [here](https://firebase.google.com/docs/app-check/custom-resource-backend#go).
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?):
```go
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](https://pkg.go.dev/firebase.google.com/go/v4/appcheck) which says you now need to create a new instance via this method instead:
```go
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](https://stackoverflow.com/questions/59342373/use-of-internal-package-not-allowed).
#### Steps to reproduce:
```go
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
}
```
Contributor guide
Assessment
This issue has not been assessed yet.