[][src]Struct firestore_db_and_auth::sessions::user::Session

pub struct Session {
    pub user_id: String,
    pub refresh_token: Option<String>,
    pub api_key: String,
    pub client: Client,
    // some fields omitted
}

An impersonated session. Firestore rules will restrict your access.

Fields

user_id: String

The firebase auth user id

refresh_token: Option<String>

The refresh token, if any. Such a token allows you to generate new, valid access tokens. This library will handle this for you, if for example your current access token expired.

api_key: String

The firebase projects API key, as defined in the credentials object

client: Client

The http client. Replace or modify the client if you have special demands like proxy support

Methods

impl Session[src]

pub fn new(
    credentials: &Credentials,
    user_id: Option<&str>,
    firebase_tokenid: Option<&str>,
    refresh_token: Option<&str>
) -> Result<Session, FirebaseError>
[src]

Create an impersonated session

If the optionally provided access token is still valid, it will be used. If the access token is not valid anymore, but the given refresh token is, it will be used to retrieve a new access token.

If neither refresh token nor access token work are provided or valid, the service account credentials will be used to generate a new impersonated refresh and access token for the given user.

If none of the parameters are given, the function will error out.

See:

  • https://firebase.google.com/docs/reference/rest/auth#section-refresh-token
  • https://firebase.google.com/docs/auth/admin/create-custom-tokens#create_custom_tokens_using_a_third-party_jwt_library

pub fn by_refresh_token(
    credentials: &Credentials,
    refresh_token: &str
) -> Result<Session, FirebaseError>
[src]

Create a new firestore user session via a valid refresh_token

Arguments:

  • credentials The credentials
  • refresh_token A refresh token.

pub fn by_user_id(
    credentials: &Credentials,
    user_id: &str,
    with_refresh_token: bool
) -> Result<Session, FirebaseError>
[src]

Create a new firestore user session with a fresh access token.

Arguments:

  • credentials The credentials
  • user_id The firebase Authentication user id. Usually a string of about 30 characters like "Io2cPph06rUWM3ABcIHguR3CIw6v1".
  • with_refresh_token A refresh token is returned as well. This should be persisted somewhere for later reuse. Google generates only a few dozens of refresh tokens before it starts to invalidate already generated ones. For short lived, immutable, non-persisting services you do not want a refresh token.

pub fn by_access_token(
    credentials: &Credentials,
    firebase_tokenid: &str
) -> Result<Session, FirebaseError>
[src]

Trait Implementations

impl FirebaseAuthBearer for Session[src]

fn access_token(&self) -> String[src]

Returns the current access token. This method will automatically refresh your access token, if it has expired.

If the refresh failed, this will

Auto Trait Implementations

impl Unpin for Session

impl !Sync for Session

impl Send for Session

impl !UnwindSafe for Session

impl !RefUnwindSafe for Session

Blanket Implementations

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> 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,