[][src]Struct firestore_db_and_auth::credentials::Credentials

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,
    // some fields omitted
}

Service account credentials

Especially the service account email is required to retrieve the public java 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: Stringprivate_key_id: Stringprivate_key: Stringclient_email: Stringclient_id: Stringapi_key: String

Methods

impl Credentials[src]

pub fn new(
    credentials_file_content: &str,
    jwks_files: &[&str]
) -> Result<Credentials, FirebaseError>
[src]

Create a Credentials object by parsing a google-service-account json string and public-key JWKs strings.

This method will also verify that the given JWKs files are matching

Example:

Assuming that your credentials file is called "firebase-service-account.json" and a downloaded jwk-set file is called "service-account-for-tests.jwks" this example embeds the file content during compile time. This avoids and http or io calls.

use firestore_db_and_auth::credentials::Credentials;

let c : Credentials = Credentials::new(include_str!("../firebase-service-account.json"),
                                        &[include_str!("../tests/service-account-for-tests.jwks")])?;

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}

pub fn verify(&self) -> Result<(), FirebaseError>[src]

pub fn from_file(credential_file: &str) -> Result<Self, FirebaseError>[src]

Create a Credentials object by reading and parsing a google-service-account json file.

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 method if this is not desired, for example in cloud functions that require fast cold start times. See Credentials::add_jwks_public_keys and Credentials::new as alternatives.

pub fn decode_secret(&self, kid: &str) -> Option<Arc<Secret>>[src]

Find the secret in the jwt set that matches the given key id, if any. Used for jws validation

pub fn add_jwks_public_keys(&mut self, jwkset: JWKSetDTO)[src]

Add a JSON Web Key Set (JWKS) to allow verification of Google access tokens.

Example:

use firestore_db_and_auth::credentials::Credentials;

let mut c : Credentials = serde_json::from_str(include_str!("../firebase-service-account.json")).unwrap();
c.add_jwks_public_keys(serde_json::from_str(include_str!("../tests/service-account-for-tests.jwks")).unwrap());
c.compute_secret().unwrap();

pub fn compute_secret(&mut self) -> Result<(), FirebaseError>[src]

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.

pub fn download_google_jwks(&mut self) -> Result<(), FirebaseError>[src]

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.

Trait Implementations

impl Default for Credentials[src]

impl Clone for Credentials[src]

impl Serialize for Credentials[src]

impl<'de> Deserialize<'de> for Credentials[src]

Auto Trait Implementations

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]

impl<T> Erased for T

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

type Err = <U as TryFrom<T>>::Err

impl<T> Typeable for T where
    T: Any

impl<T> IntoCollection<T> for T

impl<T, I> AsResult<T, I> for T where
    I: Input,