pub struct Credentials {
pub project_id: String,
pub private_key_id: String,
pub private_key: String,
pub client_email: String,
pub client_id: String,
pub api_key: String,
/* private fields */
}
Expand description
Service account credentials
Especially the service account email is required to retrieve the public json web key set (jwks) for verifying Google Firestore tokens.
The api_key is necessary for interacting with the Firestore REST API.
Internals:
The private key is used for signing JWTs (javascript web token). A signed jwt, encoded as a base64 string, can be exchanged into a refresh and access token.
Fields§
§project_id: String
§private_key_id: String
§private_key: String
§client_email: String
§client_id: String
§api_key: String
Implementations§
Source§impl Credentials
impl Credentials
Sourcepub async fn new(
credentials_file_content: &str,
) -> Result<Credentials, FirebaseError>
pub async fn new( credentials_file_content: &str, ) -> Result<Credentials, FirebaseError>
Create a Credentials
object by parsing a google-service-account json string
Example:
Assuming that your firebase service account credentials file is called “service-account-test.json” and a downloaded jwk-set file is called “service-account-test.jwks” this example embeds the file content during compile time. This avoids and http or io calls.
use firestore_db_and_auth::{Credentials};
use firestore_db_and_auth::jwt::JWKSet;
let c: Credentials = Credentials::new(include_str!("../tests/service-account-test.json")).await.unwrap()
.with_jwkset(&JWKSet::new(include_str!("../tests/service-account-test.jwks")).unwrap()).await.unwrap();
You need two JWKS files for this crate to work:
- https://www.googleapis.com/service_accounts/v1/jwk/securetoken@system.gserviceaccount.com
- https://www.googleapis.com/service_accounts/v1/jwk/{your-service-account-email}
Sourcepub async fn from_file(credential_file: &str) -> Result<Self, FirebaseError>
pub async fn from_file(credential_file: &str) -> Result<Self, FirebaseError>
Create a Credentials
object by reading and parsing a google-service-account json file.
This is a convenience method, that reads in the given credentials file and acts otherwise the same as
the Credentials::new
method.
Sourcepub async fn with_jwkset(
self,
jwks: &JWKSet,
) -> Result<Credentials, FirebaseError>
pub async fn with_jwkset( self, jwks: &JWKSet, ) -> Result<Credentials, FirebaseError>
Adds public-key JWKs to a credentials instance and returns it.
This method will also verify that the given JWKs files allow verification of Google access tokens.
This is a convenience method, you may also just use Credentials::add_jwks_public_keys
.
Sourcepub async fn download_jwkset(self) -> Result<Credentials, FirebaseError>
pub async fn download_jwkset(self) -> Result<Credentials, FirebaseError>
The public keys to verify generated tokens will be downloaded, for the given service account as well as for “securetoken@system.gserviceaccount.com”. Do not use this option if additional downloads are not desired, for example in cloud functions that require fast cold boot start times.
You can use Credentials::add_jwks_public_keys
to manually add/replace public keys later on.
Example:
Assuming that your firebase service account credentials file is called “service-account-test.json”.
use firestore_db_and_auth::{Credentials};
let c: Credentials = Credentials::new(include_str!("../tests/service-account-test.json")).await.unwrap()
.download_jwkset().await.unwrap();
Sourcepub async fn verify(&self) -> Result<(), FirebaseError>
pub async fn verify(&self) -> Result<(), FirebaseError>
Verifies that creating access tokens is possible with the given credentials and public keys. Returns an empty result type on success.
pub async fn verify_token( &self, token: &str, ) -> Result<TokenValidationResult, FirebaseError>
Sourcepub async fn decode_secret(
&self,
kid: &str,
) -> Result<Option<Arc<Secret>>, FirebaseError>
pub async fn decode_secret( &self, kid: &str, ) -> Result<Option<Arc<Secret>>, FirebaseError>
Find the secret in the jwt set that matches the given key id, if any. Used for jws validation
Sourcepub async fn add_jwks_public_keys(&self, jwkset: &JWKSet)
pub async fn add_jwks_public_keys(&self, jwkset: &JWKSet)
Add a JSON Web Key Set (JWKS) to allow verification of Google access tokens.
Example:
use firestore_db_and_auth::credentials::Credentials;
use firestore_db_and_auth::JWKSet;
let mut c : Credentials = serde_json::from_str(include_str!("../tests/service-account-test.json")).unwrap();
c.add_jwks_public_keys(&JWKSet::new(include_str!("../tests/service-account-test.jwks")).unwrap()).await;
c.compute_secret().await.unwrap();
c.verify().await.unwrap();
Sourcepub async fn download_google_jwks(&self) -> Result<(), FirebaseError>
pub async fn download_google_jwks(&self) -> Result<(), FirebaseError>
If you haven’t called Credentials::add_jwks_public_keys
to manually add public keys,
this method will download one for your google service account and one for the oauth related
securetoken@system.gserviceaccount.com service account.
Sourcepub async fn compute_secret(&mut self) -> Result<(), FirebaseError>
pub async fn compute_secret(&mut self) -> Result<(), FirebaseError>
Compute the Rsa keypair by using the private_key of the credentials file. You must call this if you have manually created a credentials object.
This is automatically invoked if you use Credentials::new
or Credentials::from_file
.
Trait Implementations§
Source§impl Clone for Credentials
impl Clone for Credentials
Source§fn clone(&self) -> Credentials
fn clone(&self) -> Credentials
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for Credentials
impl Debug for Credentials
Source§impl Default for Credentials
impl Default for Credentials
Source§fn default() -> Credentials
fn default() -> Credentials
Source§impl<'de> Deserialize<'de> for Credentials
impl<'de> Deserialize<'de> for Credentials
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Credentials
impl !RefUnwindSafe for Credentials
impl Send for Credentials
impl Sync for Credentials
impl Unpin for Credentials
impl !UnwindSafe for Credentials
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoCollection<T> for T
impl<T> IntoCollection<T> for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the foreground set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red()
and
green()
, which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg()
:
use yansi::{Paint, Color};
painted.fg(Color::White);
Set foreground color to white using white()
.
use yansi::Paint;
painted.white();
Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the background set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red()
and
on_green()
, which have the same functionality but
are pithier.
§Example
Set background color to red using fg()
:
use yansi::{Paint, Color};
painted.bg(Color::Red);
Set background color to red using on_red()
.
use yansi::Paint;
painted.on_red();
Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute
value
.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold()
and
underline()
, which have the same functionality
but are pithier.
§Example
Make text bold using attr()
:
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);
Make text bold using using bold()
.
use yansi::Paint;
painted.bold();
Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi
Quirk
value
.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask()
and
wrap()
, which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk()
:
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);
Enable wrapping using wrap()
.
use yansi::Paint;
painted.wrap();
Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition
value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted
only when both stdout
and stderr
are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);