-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(session): add create session cookie feature
* Add free standing function sessions::create_session_cookie(credentials, id_token, duration) Signed-off-by: Stephane Eintrazi <[email protected]> Signed-off-by: David Graeff <[email protected]>
- Loading branch information
1 parent
42e2d17
commit 1769d0b
Showing
3 changed files
with
194 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use firestore_db_and_auth::{ | ||
errors::FirebaseError, Credentials, FirebaseAuthBearer, sessions::session_cookie | ||
}; | ||
use crate::utils::valid_test_credentials; | ||
|
||
mod utils; | ||
|
||
fn main() -> Result<(), FirebaseError> { | ||
// Search for a credentials file in the root directory | ||
use std::path::PathBuf; | ||
let mut credential_file = PathBuf::from(env!("CARGO_MANIFEST_DIR")); | ||
credential_file.push("firebase-service-account.json"); | ||
let mut cred = Credentials::from_file(credential_file.to_str().unwrap())?; | ||
|
||
// Only download the public keys once, and cache them. | ||
let jwkset = utils::from_cache_file(credential_file.with_file_name("cached_jwks.jwks").as_path(), &cred)?; | ||
cred.add_jwks_public_keys(&jwkset); | ||
cred.verify()?; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn create_session_cookie_test() -> Result<(), FirebaseError> { | ||
let cred = valid_test_credentials()?; | ||
let user_session = utils::user_session_with_cached_refresh_token(&cred)?; | ||
|
||
assert_eq!(user_session.user_id, utils::TEST_USER_ID); | ||
assert_eq!(user_session.project_id(), cred.project_id); | ||
|
||
use chrono::Duration; | ||
session_cookie::create_session_cookie(&cred, user_session.access_token(), Duration::seconds(3600))?; | ||
|
||
Ok(()) | ||
} |
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