pub struct Session {
pub user_id: String,
pub refresh_token: Option<String>,
pub api_key: String,
pub client: Client,
/* private fields */
}
Expand description
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 for async operations. Replace or modify the client if you have special demands like proxy support
Implementations§
Source§impl Session
impl Session
Sourcepub async fn new(
credentials: &Credentials,
user_id: Option<&str>,
firebase_tokenid: Option<&str>,
refresh_token: Option<&str>,
) -> Result<Session, FirebaseError>
pub async fn new( credentials: &Credentials, user_id: Option<&str>, firebase_tokenid: Option<&str>, refresh_token: Option<&str>, ) -> Result<Session, FirebaseError>
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.
Async support: This is a blocking operation.
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
Sourcepub async fn by_refresh_token(
credentials: &Credentials,
refresh_token: &str,
) -> Result<Session, FirebaseError>
pub async fn by_refresh_token( credentials: &Credentials, refresh_token: &str, ) -> Result<Session, FirebaseError>
Create a new firestore user session via a valid refresh_token
Arguments:
credentials
The credentialsrefresh_token
A refresh token.
Async support: This is a blocking operation.
Sourcepub async fn by_user_id(
credentials: &Credentials,
user_id: &str,
with_refresh_token: bool,
) -> Result<Session, FirebaseError>
pub async fn by_user_id( credentials: &Credentials, user_id: &str, with_refresh_token: bool, ) -> Result<Session, FirebaseError>
Create a new firestore user session with a fresh access token.
Arguments:
credentials
The credentialsuser_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.
Sourcepub async fn by_access_token(
credentials: &Credentials,
access_token: &str,
) -> Result<Session, FirebaseError>
pub async fn by_access_token( credentials: &Credentials, access_token: &str, ) -> Result<Session, FirebaseError>
Create a new firestore user session by a valid access token
Remember that such a session cannot renew itself. As soon as the access token expired, no further operations can be issued by this session.
No network operation is performed, the access token is only checked for its validity.
Arguments:
credentials
The credentialsaccess_token
An access token, sometimes called a firebase id token.
Sourcepub async fn by_oauth2(
credentials: &Credentials,
access_token: String,
provider: OAuth2Provider,
request_uri: String,
with_refresh_token: bool,
) -> Result<Session, FirebaseError>
pub async fn by_oauth2( credentials: &Credentials, access_token: String, provider: OAuth2Provider, request_uri: String, with_refresh_token: bool, ) -> Result<Session, FirebaseError>
Creates a new user session with OAuth2 provider token. If user don’t exist it’s create new user in firestore
Arguments:
credentials
The credentials.access_token
access_token provided by OAuth2 provider.request_uri
The URI to which the provider redirects the user back same as from .provider
OAuth2Provider enum: Apple, AppleGameCenter, Facebook, GitHub, Google, GooglePlayGames, LinkedIn, Microsoft, Twitter, Yahoo.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.
Trait Implementations§
Source§impl FirebaseAuthBearer for Session
impl FirebaseAuthBearer for Session
Source§fn access_token<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = String> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn access_token<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = String> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Returns the current access token. This method will automatically refresh your access token, if it has expired.
If the refresh failed, this will return an empty string.
Source§fn project_id(&self) -> &str
fn project_id(&self) -> &str
Auto Trait Implementations§
impl Freeze for Session
impl !RefUnwindSafe for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl !UnwindSafe for Session
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);