Skip to content

Commit 604af8d

Browse files
committed
Refactor token verifier URL generation
1 parent 6c999a4 commit 604af8d

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

appcheck/appcheck.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var JWKSUrl = "https://firebaseappcheck.googleapis.com/v1beta/jwks"
3636

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

39-
const tokenVerificationUrlFormat = "https://firebaseappcheck.googleapis.com/v1beta/projects/%s:verifyAppCheckToken"
39+
const tokenVerifierBaseUrl = "https://firebaseappcheck.googleapis.com"
4040

4141
var (
4242
// ErrIncorrectAlgorithm is returned when the token is signed with a non-RSA256 algorithm.
@@ -72,9 +72,9 @@ type DecodedAppCheckToken struct {
7272

7373
// Client is the interface for the Firebase App Check service.
7474
type Client struct {
75-
projectID string
76-
jwks *keyfunc.JWKS
77-
tokenVerificationUrl string
75+
projectID string
76+
jwks *keyfunc.JWKS
77+
tokenVerifierUrl string
7878
}
7979

8080
// NewClient creates a new instance of the Firebase App Check Client.
@@ -92,9 +92,9 @@ func NewClient(ctx context.Context, conf *internal.AppCheckConfig) (*Client, err
9292
}
9393

9494
return &Client{
95-
projectID: conf.ProjectID,
96-
jwks: jwks,
97-
tokenVerificationUrl: fmt.Sprintf(tokenVerificationUrlFormat, conf.ProjectID),
95+
projectID: conf.ProjectID,
96+
jwks: jwks,
97+
tokenVerifierUrl: buildTokenVerifierUrl(conf.ProjectID),
9898
}, nil
9999
}
100100

@@ -212,7 +212,7 @@ func (c *Client) VerifyOneTimeToken(token string) (*DecodedAppCheckToken, error)
212212

213213
bodyReader := bytes.NewReader([]byte(fmt.Sprintf(`{"app_check_token":%s}`, token)))
214214

215-
resp, err := http.Post(c.tokenVerificationUrl, "application/json", bodyReader)
215+
resp, err := http.Post(c.tokenVerifierUrl, "application/json", bodyReader)
216216

217217
if err != nil {
218218
return nil, err
@@ -235,6 +235,10 @@ func (c *Client) VerifyOneTimeToken(token string) (*DecodedAppCheckToken, error)
235235
return decodedAppCheckToken, nil
236236
}
237237

238+
func buildTokenVerifierUrl(projectId string) string {
239+
return fmt.Sprintf("%s/v1beta/projects/%s:verifyAppCheckToken", tokenVerifierBaseUrl, projectId)
240+
}
241+
238242
func contains(s []string, str string) bool {
239243
for _, v := range s {
240244
if v == str {

appcheck/appcheck_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func TestVerifyOneTimeToken(t *testing.T) {
7979
t.Fatalf("error creating new client: %v", err)
8080
}
8181

82-
client.tokenVerificationUrl = appCheckVerifyMockServer.URL
82+
client.tokenVerifierUrl = appCheckVerifyMockServer.URL
8383

8484
_, err = client.VerifyOneTimeToken(token)
8585

0 commit comments

Comments
 (0)