-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
198 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,13 @@ import ( | |
"firebase.google.com/go/v4/internal" | ||
) | ||
|
||
const ( | ||
algorithmNone = "none" | ||
algorithmRS256 = "RS256" | ||
|
||
emulatorEmail = "[email protected]" | ||
) | ||
|
||
type jwtHeader struct { | ||
Algorithm string `json:"alg"` | ||
Type string `json:"typ"` | ||
|
@@ -88,6 +95,7 @@ type serviceAccount struct { | |
|
||
// cryptoSigner is used to cryptographically sign data, and query the identity of the signer. | ||
type cryptoSigner interface { | ||
Algorithm() string | ||
Sign(context.Context, []byte) ([]byte, error) | ||
Email(context.Context) (string, error) | ||
} | ||
|
@@ -133,6 +141,10 @@ func newServiceAccountSigner(sa serviceAccount) (*serviceAccountSigner, error) { | |
}, nil | ||
} | ||
|
||
func (s serviceAccountSigner) Algorithm() string { | ||
return algorithmRS256 | ||
} | ||
|
||
func (s serviceAccountSigner) Sign(ctx context.Context, b []byte) ([]byte, error) { | ||
hash := sha256.New() | ||
hash.Write(b) | ||
|
@@ -173,6 +185,10 @@ func newIAMSigner(ctx context.Context, config *internal.AuthConfig) (*iamSigner, | |
}, nil | ||
} | ||
|
||
func (s iamSigner) Algorithm() string { | ||
return algorithmRS256 | ||
} | ||
|
||
func (s iamSigner) Sign(ctx context.Context, b []byte) ([]byte, error) { | ||
account, err := s.Email(ctx) | ||
if err != nil { | ||
|
@@ -245,3 +261,17 @@ func (s iamSigner) callMetadataService(ctx context.Context) (string, error) { | |
|
||
return result, nil | ||
} | ||
|
||
type emulatedSigner struct{} | ||
|
||
func (s emulatedSigner) Algorithm() string { | ||
return algorithmNone | ||
} | ||
|
||
func (s emulatedSigner) Email(context.Context) (string, error) { | ||
return emulatorEmail, nil | ||
} | ||
|
||
func (s emulatedSigner) Sign(context.Context, []byte) ([]byte, error) { | ||
return []byte(""), nil | ||
} |
Oops, something went wrong.