-
Notifications
You must be signed in to change notification settings - Fork 306
Support for creating custom tokens without service account credentials #183
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
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
b10c89a
Ability to sign tokens without a service account credential
hiranya911 0a138f3
Temp fixes for unit tests
hiranya911 bc7ae70
Cleaned up the new JWT sign logic
hiranya911 664e55d
Cleaned up the new JWT sign logic
hiranya911 be79bb7
Updated changelog
hiranya911 3ec0e41
Moved token issuer to CyptoSigner interface
hiranya911 8183e7f
Merged with master
hiranya911 a2a20b2
Modifications to the token sign protocol (go/firebase-admin-sign)
hiranya911 eac02ca
Caching the token factory after first call
hiranya911 9c648b7
Updated documentation
hiranya911 3a72f63
Merged with master
hiranya911 5912990
Merged with master
hiranya911 9eb007e
Updated API docs
hiranya911 9567164
Fixing style error
hiranya911 9504161
Updated error message
hiranya911 d577e49
Updated documentation
hiranya911 3c4c391
Renamed serviceAccount to serviceAccountId
hiranya911 0f05b65
Fixed lint error
hiranya911 eb465ad
Added snippet; updated error message to sync with documentation
hiranya911 e45add3
Minor API doc updates
hiranya911 8e3f4ec
Merged with master
hiranya911 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
47 changes: 47 additions & 0 deletions
47
src/main/java/com/google/firebase/auth/internal/CryptoSigner.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * Copyright 2018 Google Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.google.firebase.auth.internal; | ||
|
|
||
| import com.google.firebase.internal.NonNull; | ||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * Represents an object that can be used to cryptographically sign data. Mainly used for signing | ||
| * custom JWT tokens issued to Firebase users. | ||
| * | ||
| * <p>See {@link com.google.firebase.auth.FirebaseAuth#createCustomToken(String)}. | ||
| */ | ||
| interface CryptoSigner { | ||
|
|
||
| /** | ||
| * Signs the given payload. | ||
| * | ||
| * @param payload Data to be signed | ||
| * @return Signature as a byte array | ||
| * @throws IOException If an error occurs during signing | ||
| */ | ||
| @NonNull | ||
| byte[] sign(@NonNull byte[] payload) throws IOException; | ||
|
|
||
| /** | ||
| * Returns the client email of the service account used to sign payloads. | ||
| * | ||
| * @return A service account client email | ||
| */ | ||
| @NonNull | ||
| String getAccount(); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I remember my Java 101 class correctly, then you don't need to use an AtomicReference here since you are grabbing a lock already.
http://www.cs.umd.edu/users/pugh/java/memoryModel/jsr-133-faq.html#synchronization
"Synchronization ensures that memory writes by a thread before or during a synchronized block are made visible in a predictable manner to other threads which synchronize on the same monitor. "
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then we'd have to make the variable
volatile, to get the double-checked locking semantics to work correctly: https://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.htmlI don't really have a preference. Drop the AtomicRef and switch to a volatile variable?