cpolis/cmd/backend/firebase.go

45 lines
741 B
Go
Raw Normal View History

2024-08-09 17:07:27 +02:00
package backend
import (
"context"
firebase "firebase.google.com/go/v4"
"firebase.google.com/go/v4/auth"
"google.golang.org/api/option"
)
type Client struct {
*auth.Client
}
2024-08-23 21:45:10 +02:00
func NewClient(c *Config) (*Client, error) {
2024-08-09 17:07:27 +02:00
var err error
client := new(Client)
ctx := context.Background()
2024-08-23 21:45:10 +02:00
opt := option.WithCredentialsFile(c.FirebaseKey)
2024-08-09 17:07:27 +02:00
app, err := firebase.NewApp(ctx, nil, opt)
if err != nil {
return nil, err
}
client.Client, err = app.Auth(ctx)
if err != nil {
return nil, err
}
return client, nil
}
2024-08-17 18:21:56 +02:00
func (c *Client) Verify(idToken string) (*auth.Token, error) {
2024-08-09 17:07:27 +02:00
ctx := context.Background()
2024-08-17 18:21:56 +02:00
token, err := c.VerifyIDTokenAndCheckRevoked(ctx, idToken)
if err != nil {
return nil, err
}
return token, nil
2024-08-09 17:07:27 +02:00
}