[go: nahoru, domu]

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

feat(appcheck): Add App Check token verification #484

Merged
merged 20 commits into from
Oct 26, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix lint errors by adding more comments.
  • Loading branch information
bamnet committed Feb 9, 2022
commit 556e159ff41b91769523ac4ea06aa051dc628c2a
26 changes: 17 additions & 9 deletions appcheck/appcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,27 @@ import (
"firebase.google.com/go/v4/internal"
)

const (
AppCheckIssuer = "https://firebaseappcheck.googleapis.com/"
JWKSUrl = "https://firebaseappcheck.googleapis.com/v1beta/jwks"
)
// JWKSUrl is the URL of the JWKS used to verify App Check tokens.
const JWKSUrl = "https://firebaseappcheck.googleapis.com/v1beta/jwks"

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

var (
// ErrIncorrectAlgorithm is returned when the token is signed with a non-RSA256 algorithm.
ErrIncorrectAlgorithm = errors.New("token has incorrect algorithm")
ErrTokenType = errors.New("token has incorrect type")
ErrTokenClaims = errors.New("token has incorrect claims")
ErrTokenAudience = errors.New("token has incorrect audience")
ErrTokenIssuer = errors.New("token has incorrect issuer")
ErrTokenSubject = errors.New("token has empty or missing subject")
// ErrTokenType is returned when the token is not a JWT.
ErrTokenType = errors.New("token has incorrect type")
// ErrTokenClaims is returned when the token claims cannot be decoded.
ErrTokenClaims = errors.New("token has incorrect claims")
// ErrTokenAudience is returned when the token audience does not match the current project.
ErrTokenAudience = errors.New("token has incorrect audience")
// ErrTokenIssuer is returned when the token issuer does not match Firebase's App Check service.
ErrTokenIssuer = errors.New("token has incorrect issuer")
// ErrTokenSubject is returned when the token subject is empty or missing.
ErrTokenSubject = errors.New("token has empty or missing subject")
)

// VerifiedToken represents a verified App Check token.
type VerifiedToken struct {
bamnet marked this conversation as resolved.
Show resolved Hide resolved
Iss string
Sub string
Expand All @@ -36,6 +43,7 @@ type VerifiedToken struct {
AppID string
}

// Client is the interface for the Firebase App Check service.
type Client struct {
projectID string

bamnet marked this conversation as resolved.
Show resolved Hide resolved
Expand Down