Skip to content

Commit eccb159

Browse files
chemidyavishalom
authored andcommitted
use identitytoolkit/v3 go client instead of makeHTTPCall (#60)
* use identitytoolkit/v3 go client instead of makeHTTPCall * remove unnecessary if because empty values are not sent with identitytoolkit * refactoring to avoid multiple header set * change execute func to setHeader * remove url from Client type, rename relayingpartyCall interface + fix providerID mistake * change rawId value in test to 'testuid'
1 parent 237dc19 commit eccb159

File tree

6 files changed

+203
-101
lines changed

6 files changed

+203
-101
lines changed

auth/auth.go

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,16 @@ import (
2222
"encoding/pem"
2323
"errors"
2424
"fmt"
25-
"net/http"
2625
"strings"
2726

2827
"firebase.google.com/go/internal"
2928
"golang.org/x/net/context"
29+
"google.golang.org/api/identitytoolkit/v3"
3030
"google.golang.org/api/transport"
3131
)
3232

3333
const firebaseAudience = "https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit"
3434
const googleCertURL = "https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com"
35-
const idToolKitURL = "https://www.googleapis.com/identitytoolkit/v3/relyingparty/"
3635
const issuerPrefix = "https://securetoken.google.com/"
3736
const tokenExpSeconds = 3600
3837

@@ -64,10 +63,10 @@ type Token struct {
6463
// by Firebase backend services.
6564
type Client struct {
6665
hc *internal.HTTPClient
66+
is *identitytoolkit.Service
6767
ks keySource
6868
projectID string
6969
snr signer
70-
url string
7170
version string
7271
}
7372

@@ -118,32 +117,21 @@ func NewClient(ctx context.Context, c *internal.AuthConfig) (*Client, error) {
118117
return nil, err
119118
}
120119

120+
is, err := identitytoolkit.New(hc)
121+
if err != nil {
122+
return nil, err
123+
}
124+
121125
return &Client{
122126
hc: &internal.HTTPClient{Client: hc},
127+
is: is,
123128
ks: newHTTPKeySource(googleCertURL, hc),
124129
projectID: c.ProjectID,
125130
snr: snr,
126-
url: idToolKitURL,
127131
version: "Go/Admin/" + c.Version,
128132
}, nil
129133
}
130134

131-
// Passes the request struct, returns a byte array of the json
132-
func (c *Client) makeHTTPCall(ctx context.Context, serviceName string, payload interface{}, result interface{}) error {
133-
versionHeader := internal.WithHeader("X-Client-Version", c.version)
134-
request := &internal.Request{
135-
Method: http.MethodPost,
136-
URL: c.url + serviceName,
137-
Body: internal.NewJSONEntity(payload),
138-
Opts: []internal.HTTPOption{versionHeader},
139-
}
140-
resp, err := c.hc.Do(ctx, request)
141-
if err != nil {
142-
return err
143-
}
144-
return resp.Unmarshal(http.StatusOK, result)
145-
}
146-
147135
// CustomToken creates a signed custom authentication token with the specified user ID. The resulting
148136
// JWT can be used in a Firebase client SDK to trigger an authentication flow. See
149137
// https://firebase.google.com/docs/auth/admin/create-custom-tokens#sign_in_using_custom_tokens_on_clients

0 commit comments

Comments
 (0)